#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main()
{
typedef struct
{
int n_adults;
int n_kids;
char day[10];
char weather[10];
} daydata;
daydata record[30];
FILE*f;
char line[121];
char*item;
int reccount = 0;
int k;
/*Open file*/
f = fopen("newstuff.txt", "r");
/*read file line by line*/
while(fgets(line,120,f))
{
printf("%s", line);
item = strtok(line, " ");
record[reccount].n_adults = atoi(item);
item = strtok(NULL, " ");
record[reccount].n_kids = atoi(item);
item = strtok(NULL, " ");
strcopy(record[reccount].day, item);
item = strtok(NULL, "\n");
strcpy(record[reccount].weather, item);
printf("%s\n", record[reccount].day);
reccount++;
}
/* close file */
fclose(f);
/*loop through and report data*/
printf("Weather Record\n");
for(k = 0; k < reccount; k++)
{
printf("it is %s\n", record[k].weather);
}
}
Error as below:
Quote
*****@ubuntu:~/week10$ gcc -o ArrayStruct1 ArrayStruct1.c
/tmp/ccLtl4bl.o: In function `main':
ArrayStruct1.c:(.text+0x15e): undefined reference to `strcopy'
collect2: ld returned 1 exit status
/tmp/ccLtl4bl.o: In function `main':
ArrayStruct1.c:(.text+0x15e): undefined reference to `strcopy'
collect2: ld returned 1 exit status


Sign In
Create Account


Back to top









