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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 95 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]
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply