ChefNinja
06-25-2002, 08:47 AM
This is not my code, a friend of mine asked me to post this here for him... I don't know why he couldn't just do it himself.. but whatever.
I don't know enough C to fix this for him, so maybe you guys can help...
#include <stdio.h>
#include <stdlib.h>
void grabData(int dat);
int processData(int *dat);
/* This is where it all kicks off */
int main() {
/* Array to store the file data */
int elements[30];
/* Pointer to element array */
int *data;
/* Result */
int result = 0;
/* Initialise the element array */
memset(elements, 0, (sizeof(integer) * 30));
data = &elements[0];
printf('Simple data processing script\n');
printf("by slyfx [www.slyfx.com]\n\n");
/* Grab the data from the file */
grabData(*data);
/* Process the data and grab the result */
result = processData(data);
printf("The result of the processing is %s\n", result);
return(0);
}
/* Opens the data file and read it in */
void grabData(int *dat) {
int loop;
FILE *fp;
fp = fopen("data.sly", "r");
if (fp == NULL) {
perror("Failed to open file for reading!\n");
exit(1);
}
/* Grab the lines */
for(loop = 0; loop < 30; loop++) {
if (fscanf(fp, "%d", dat[loop]) == EOF) {
perror("Fatal: not enough data!\n");
exit(1);
}
}
*(dat + 1) = 20;
fclose(fp);
}
/* Process the data */
int processData(int *dat) {
int loop;
int res = 0;
for(loop = 0; loop < 30; loop++) {
res += (dat[loop] ? (dat[loop] - 50) : 69) ? dat[loop] : 69;
while (res > 300000) {
res -= dat[loop] ? dat[loop] : 169;
}
}
return *res;
}
Here's the error messages given to me by the compiler when I run it...
(27) : warning C4013: 'memset' undefined; assuming extern returning int
(27) : error C2065: 'integer' : undeclared identifier
(46) : warning C4028: formal parameter 1 different from declaration
(81) : error C2100: illegal indirection
Really, I have no idea what is wrong. I am so newb :\
I don't know enough C to fix this for him, so maybe you guys can help...
#include <stdio.h>
#include <stdlib.h>
void grabData(int dat);
int processData(int *dat);
/* This is where it all kicks off */
int main() {
/* Array to store the file data */
int elements[30];
/* Pointer to element array */
int *data;
/* Result */
int result = 0;
/* Initialise the element array */
memset(elements, 0, (sizeof(integer) * 30));
data = &elements[0];
printf('Simple data processing script\n');
printf("by slyfx [www.slyfx.com]\n\n");
/* Grab the data from the file */
grabData(*data);
/* Process the data and grab the result */
result = processData(data);
printf("The result of the processing is %s\n", result);
return(0);
}
/* Opens the data file and read it in */
void grabData(int *dat) {
int loop;
FILE *fp;
fp = fopen("data.sly", "r");
if (fp == NULL) {
perror("Failed to open file for reading!\n");
exit(1);
}
/* Grab the lines */
for(loop = 0; loop < 30; loop++) {
if (fscanf(fp, "%d", dat[loop]) == EOF) {
perror("Fatal: not enough data!\n");
exit(1);
}
}
*(dat + 1) = 20;
fclose(fp);
}
/* Process the data */
int processData(int *dat) {
int loop;
int res = 0;
for(loop = 0; loop < 30; loop++) {
res += (dat[loop] ? (dat[loop] - 50) : 69) ? dat[loop] : 69;
while (res > 300000) {
res -= dat[loop] ? dat[loop] : 169;
}
}
return *res;
}
Here's the error messages given to me by the compiler when I run it...
(27) : warning C4013: 'memset' undefined; assuming extern returning int
(27) : error C2065: 'integer' : undeclared identifier
(46) : warning C4028: formal parameter 1 different from declaration
(81) : error C2100: illegal indirection
Really, I have no idea what is wrong. I am so newb :\