Page 1 of 1

C tryingFgets.c > main() 1 #include 2 #include 3 #include 4 5 struct carInfo{ 6 7 char*

Posted: Sat Nov 27, 2021 10:26 am
by answerhappygod
C Tryingfgets C Main 1 Include Stdio H 2 Include Stdlib H 3 Include String H 4 5 Struct Carinfo 6 7 Char 1
C Tryingfgets C Main 1 Include Stdio H 2 Include Stdlib H 3 Include String H 4 5 Struct Carinfo 6 7 Char 1 (72.83 KiB) Viewed 97 times
When trying to save a sting from a txt file to my program i am
only getting NULL and these errors. Do you see anything wrong with
my program?
C tryingFgets.c > main() 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 struct carInfo{ 6 7 char* make; 8 int year; 9 int cost; 10 char* city; 11 char* state; 12 13 }group[70]; 14 15 16 17 int main() { 18 19 20 21 int i=0; 22 int userChoice; struct carInfo group [70]; 23 24 25 26 27 28 FILE *fp; fp = fopen("program.txt", "r"); 29 30 if (fp == NULL) { printf("There is a error opening the file!"); 31

printf("There is a error opening the file!"); 31 32 33 } 34 35 char* txtHolder; 36 37 38 39 10 11 12 13 14 15 16 17 while (i<70, i++) { fgets(*txtHolder, 255, fp); char* sndHolder = strtok (*txtHolder, ","); group.make = *sndHolder; sndHolder = strtok(NULL,", "); group.year = *sndHolder; sndHolder = strtok (NULL,","); group.cost = *sndHolder; sndHolder = strtok (NULL,", "); group.city = *sndHolder; sndHolder = strtok (NULL,", "); group.state = *sndHolder; = 18 19 50 51 52 53 54 } 55 printf("%s", group[@].make); 56 57 58 59 fclose(fp); 50 51 return 0;

(null)[1] + Done

38 { 39 40 41 42 43 44 45 46 47 48 fgets(*txtHolder, 255, fp); char* sndHolder = strtok(*txtHolder,", "); group.make = *sndHolder; sndHolder = strtok (NULL,", "); group.year = *sndHolder; sndHolder = strtok (NULL,", "); group.cost = *sndHolder; sndHolder = strtok (NULL,", "); group.city = *sndHolder; sndHolder = strtok (NULL,", "); group.state = *sndHolder; 49 } 50 51 52 53 54 55 56 57 58 59 printf("%s", group[0].make); fclose(fp); 60 61 return 0; PROBLEMS 2 OUTPUT TERMINAL DEBUG CONSOLE v C tryingFgets.c 2 A passing argument 1 of 'fgets' makes pointer from integer without a cast [-Wint-conversion] gcc [43, 15] A passing argument 1 of 'strtok' makes pointer from integer without a cast [-Wint-conversion) gcc [44, 34]