Hey you guys Im not really good with structures and I was wonderingif someone co
ID: 3618905 • Letter: H
Question
Hey you guys Im not really good with structures and I was wonderingif someone could help me with this problem. I have to prompt theuser for a text file (random.txt) and then store the contentsinto a structure so I can do so file manipulation. But I dont knowhow to put the contents into a structure, if someone could help meout with that im pretty much good to go. Here is what the contentslook like in the file: random.txt ;Gates, William, H, 1.89 Jobs, Steven, P, 2.56 Brin, Sergey, , 3.89 Page, Lawrence, , 3.77 Buffett, Warren, E, 3.34
My code: #include <stdio.h> #include <stdlib.h> #define TEN 10 #define THREE 3 #define TWENTY 20 #define FIFTY 50 #define ONE_THOUSAND 1000
typedef struct { char first_name[TEN]; char middle_name[THREE]; char last_name[TWENTY]; double users_gpa[TEN];
} format_of_file;
int main () { /* Declarations: File I/O, */ FILE *inp, *outp; char first_file[FIFTY], second_file[FIFTY]; format_of_file organized[ONE_THOUSAND]; /* Get users inputs */ printf("Enter the input file name: "); scanf("%s", first_file); printf("Enter the output file name: "); scanf("%s", second_file); inp = fopen(first_file, "r"); outp = fopen(second_file, "w"); /* Test if both files for validity */ if (inp == NULL) { perror("Invalid File"); exit(EXIT_FAILURE); } if (outp == NULL) { perror("Invalid File"); exit(EXIT_FAILURE); }
return 0; }
Thanks you guys. I just need help figuring out how to put thatcontent into a structure. This is different for me because ivenever dealt with , before in a text file. random.txt ;
Gates, William, H, 1.89 Jobs, Steven, P, 2.56 Brin, Sergey, , 3.89 Page, Lawrence, , 3.77 Buffett, Warren, E, 3.34
My code: #include <stdio.h> #include <stdlib.h> #define TEN 10 #define THREE 3 #define TWENTY 20 #define FIFTY 50 #define ONE_THOUSAND 1000
typedef struct { char first_name[TEN]; char middle_name[THREE]; char last_name[TWENTY]; double users_gpa[TEN];
} format_of_file;
int main () { /* Declarations: File I/O, */ FILE *inp, *outp; char first_file[FIFTY], second_file[FIFTY]; format_of_file organized[ONE_THOUSAND]; /* Get users inputs */ printf("Enter the input file name: "); scanf("%s", first_file); printf("Enter the output file name: "); scanf("%s", second_file); inp = fopen(first_file, "r"); outp = fopen(second_file, "w"); /* Test if both files for validity */ if (inp == NULL) { perror("Invalid File"); exit(EXIT_FAILURE); } if (outp == NULL) { perror("Invalid File"); exit(EXIT_FAILURE); }
return 0; }
Thanks you guys. I just need help figuring out how to put thatcontent into a structure. This is different for me because ivenever dealt with , before in a text file. Gates, William, H, 1.89 Jobs, Steven, P, 2.56 Brin, Sergey, , 3.89 Page, Lawrence, , 3.77 Buffett, Warren, E, 3.34
My code: #include <stdio.h> #include <stdlib.h> #define TEN 10 #define THREE 3 #define TWENTY 20 #define FIFTY 50 #define ONE_THOUSAND 1000
typedef struct { char first_name[TEN]; char middle_name[THREE]; char last_name[TWENTY]; double users_gpa[TEN];
} format_of_file;
int main () { /* Declarations: File I/O, */ FILE *inp, *outp; char first_file[FIFTY], second_file[FIFTY]; format_of_file organized[ONE_THOUSAND]; /* Get users inputs */ printf("Enter the input file name: "); scanf("%s", first_file); printf("Enter the output file name: "); scanf("%s", second_file); inp = fopen(first_file, "r"); outp = fopen(second_file, "w"); /* Test if both files for validity */ if (inp == NULL) { perror("Invalid File"); exit(EXIT_FAILURE); } if (outp == NULL) { perror("Invalid File"); exit(EXIT_FAILURE); }
return 0; }
Thanks you guys. I just need help figuring out how to put thatcontent into a structure. This is different for me because ivenever dealt with , before in a text file. #include <stdio.h> #include <stdlib.h> #define TEN 10 #define THREE 3 #define TWENTY 20 #define FIFTY 50 #define ONE_THOUSAND 1000
typedef struct { char first_name[TEN]; char middle_name[THREE]; char last_name[TWENTY]; double users_gpa[TEN];
} format_of_file;
int main () { /* Declarations: File I/O, */ FILE *inp, *outp; char first_file[FIFTY], second_file[FIFTY]; format_of_file organized[ONE_THOUSAND]; /* Get users inputs */ printf("Enter the input file name: "); scanf("%s", first_file); printf("Enter the output file name: "); scanf("%s", second_file); inp = fopen(first_file, "r"); outp = fopen(second_file, "w"); /* Test if both files for validity */ if (inp == NULL) { perror("Invalid File"); exit(EXIT_FAILURE); } if (outp == NULL) { perror("Invalid File"); exit(EXIT_FAILURE); }
return 0; }
Thanks you guys. I just need help figuring out how to put thatcontent into a structure. This is different for me because ivenever dealt with , before in a text file.