C - File with both Integer and String (Division Problems)
I have a task, I am working with few days already, I am going crazy, Google doesn't help, only choice is to ask here.
I am a total beginner in C.
I have a file, ordinary .txt file.
Mathematics 5 1 2 3 4 5
Physics 6 1 2 3 4 5 6
Design 7 1 2 3 4 5 6 7
First word is a "course", first number is the amount of grades that are in this course, for example Math, first number is 5 and I have 5 grades, 1 2 3 4 5, same with other courses.
I need to create 3 different arrays.
Array of courses ("Mathematics", "Physics", "Design") and of course not with hands, but by taking all of these from FILE.
Array of amount of grades (First number on each line),
Array of average grades (All numbers except the first one on each line),
MY MAIN PROBLEM:
I can't divide my .txt file so that I get only string (Mathematics, Physics and Design).
Here is my code, most logical things I came up with, but fscanf unfortunately tells me that I can't convert STRING to INTEGER.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main () {
FILE *fp;
fp = fopen("C:\Project\project.txt", "r"); //opening already created file
int grades[500];
char courses[300];
for (int i = 0; i < 300; ++i) {
fscanf(fp, "%s", &courses[i]);
if(isdigit(courses[i]))
fscanf(fp, "%d", &grades[i]);
}
fclose(fp);
return(0);
}
Basically this code doesn't work. Program thinks about text in the file as String, I try to take it out as char and later send it to its respective arrays, but I physically can't do it.
Once again, First I need to take those course names, "Mathematics", "Physics" and "Design" as string and later to move on to numbers.
Thanks in advance
c arrays string file
add a comment |
I have a task, I am working with few days already, I am going crazy, Google doesn't help, only choice is to ask here.
I am a total beginner in C.
I have a file, ordinary .txt file.
Mathematics 5 1 2 3 4 5
Physics 6 1 2 3 4 5 6
Design 7 1 2 3 4 5 6 7
First word is a "course", first number is the amount of grades that are in this course, for example Math, first number is 5 and I have 5 grades, 1 2 3 4 5, same with other courses.
I need to create 3 different arrays.
Array of courses ("Mathematics", "Physics", "Design") and of course not with hands, but by taking all of these from FILE.
Array of amount of grades (First number on each line),
Array of average grades (All numbers except the first one on each line),
MY MAIN PROBLEM:
I can't divide my .txt file so that I get only string (Mathematics, Physics and Design).
Here is my code, most logical things I came up with, but fscanf unfortunately tells me that I can't convert STRING to INTEGER.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main () {
FILE *fp;
fp = fopen("C:\Project\project.txt", "r"); //opening already created file
int grades[500];
char courses[300];
for (int i = 0; i < 300; ++i) {
fscanf(fp, "%s", &courses[i]);
if(isdigit(courses[i]))
fscanf(fp, "%d", &grades[i]);
}
fclose(fp);
return(0);
}
Basically this code doesn't work. Program thinks about text in the file as String, I try to take it out as char and later send it to its respective arrays, but I physically can't do it.
Once again, First I need to take those course names, "Mathematics", "Physics" and "Design" as string and later to move on to numbers.
Thanks in advance
c arrays string file
when the program iterates through your file, your very first fscanf successfully retrieves the course, then checks the succeeding values. so once your loop iterates again, then the fscanf will check on the digit side, and you are fetching it as a string... might want to consider having a fixed length grade to scan only once with "%s %d %d %d %d %d ..."
– arjayosma
Nov 14 '18 at 4:09
1
The best thing to do is see one of the teacher's assistants. You need a lot more help than can be provided in a stack overflow Q&A.
– user3386109
Nov 14 '18 at 4:14
1
A hint - Take it line by line. For the first line you first scan the Name - put that in the courses array. Then scan the amount of grades. Put that in amount of grades array. Then run a loop for no of grades (scanned previously, say n). Scan n grades. Calculate the average. Put the average in the average array. Repeat entire thing 3 times for 3 lines (or until end of file)
– Rishikesh Raje
Nov 14 '18 at 4:24
add a comment |
I have a task, I am working with few days already, I am going crazy, Google doesn't help, only choice is to ask here.
I am a total beginner in C.
I have a file, ordinary .txt file.
Mathematics 5 1 2 3 4 5
Physics 6 1 2 3 4 5 6
Design 7 1 2 3 4 5 6 7
First word is a "course", first number is the amount of grades that are in this course, for example Math, first number is 5 and I have 5 grades, 1 2 3 4 5, same with other courses.
I need to create 3 different arrays.
Array of courses ("Mathematics", "Physics", "Design") and of course not with hands, but by taking all of these from FILE.
Array of amount of grades (First number on each line),
Array of average grades (All numbers except the first one on each line),
MY MAIN PROBLEM:
I can't divide my .txt file so that I get only string (Mathematics, Physics and Design).
Here is my code, most logical things I came up with, but fscanf unfortunately tells me that I can't convert STRING to INTEGER.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main () {
FILE *fp;
fp = fopen("C:\Project\project.txt", "r"); //opening already created file
int grades[500];
char courses[300];
for (int i = 0; i < 300; ++i) {
fscanf(fp, "%s", &courses[i]);
if(isdigit(courses[i]))
fscanf(fp, "%d", &grades[i]);
}
fclose(fp);
return(0);
}
Basically this code doesn't work. Program thinks about text in the file as String, I try to take it out as char and later send it to its respective arrays, but I physically can't do it.
Once again, First I need to take those course names, "Mathematics", "Physics" and "Design" as string and later to move on to numbers.
Thanks in advance
c arrays string file
I have a task, I am working with few days already, I am going crazy, Google doesn't help, only choice is to ask here.
I am a total beginner in C.
I have a file, ordinary .txt file.
Mathematics 5 1 2 3 4 5
Physics 6 1 2 3 4 5 6
Design 7 1 2 3 4 5 6 7
First word is a "course", first number is the amount of grades that are in this course, for example Math, first number is 5 and I have 5 grades, 1 2 3 4 5, same with other courses.
I need to create 3 different arrays.
Array of courses ("Mathematics", "Physics", "Design") and of course not with hands, but by taking all of these from FILE.
Array of amount of grades (First number on each line),
Array of average grades (All numbers except the first one on each line),
MY MAIN PROBLEM:
I can't divide my .txt file so that I get only string (Mathematics, Physics and Design).
Here is my code, most logical things I came up with, but fscanf unfortunately tells me that I can't convert STRING to INTEGER.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main () {
FILE *fp;
fp = fopen("C:\Project\project.txt", "r"); //opening already created file
int grades[500];
char courses[300];
for (int i = 0; i < 300; ++i) {
fscanf(fp, "%s", &courses[i]);
if(isdigit(courses[i]))
fscanf(fp, "%d", &grades[i]);
}
fclose(fp);
return(0);
}
Basically this code doesn't work. Program thinks about text in the file as String, I try to take it out as char and later send it to its respective arrays, but I physically can't do it.
Once again, First I need to take those course names, "Mathematics", "Physics" and "Design" as string and later to move on to numbers.
Thanks in advance
c arrays string file
c arrays string file
asked Nov 14 '18 at 3:53
Aleksandre Sikharulidze
225
225
when the program iterates through your file, your very first fscanf successfully retrieves the course, then checks the succeeding values. so once your loop iterates again, then the fscanf will check on the digit side, and you are fetching it as a string... might want to consider having a fixed length grade to scan only once with "%s %d %d %d %d %d ..."
– arjayosma
Nov 14 '18 at 4:09
1
The best thing to do is see one of the teacher's assistants. You need a lot more help than can be provided in a stack overflow Q&A.
– user3386109
Nov 14 '18 at 4:14
1
A hint - Take it line by line. For the first line you first scan the Name - put that in the courses array. Then scan the amount of grades. Put that in amount of grades array. Then run a loop for no of grades (scanned previously, say n). Scan n grades. Calculate the average. Put the average in the average array. Repeat entire thing 3 times for 3 lines (or until end of file)
– Rishikesh Raje
Nov 14 '18 at 4:24
add a comment |
when the program iterates through your file, your very first fscanf successfully retrieves the course, then checks the succeeding values. so once your loop iterates again, then the fscanf will check on the digit side, and you are fetching it as a string... might want to consider having a fixed length grade to scan only once with "%s %d %d %d %d %d ..."
– arjayosma
Nov 14 '18 at 4:09
1
The best thing to do is see one of the teacher's assistants. You need a lot more help than can be provided in a stack overflow Q&A.
– user3386109
Nov 14 '18 at 4:14
1
A hint - Take it line by line. For the first line you first scan the Name - put that in the courses array. Then scan the amount of grades. Put that in amount of grades array. Then run a loop for no of grades (scanned previously, say n). Scan n grades. Calculate the average. Put the average in the average array. Repeat entire thing 3 times for 3 lines (or until end of file)
– Rishikesh Raje
Nov 14 '18 at 4:24
when the program iterates through your file, your very first fscanf successfully retrieves the course, then checks the succeeding values. so once your loop iterates again, then the fscanf will check on the digit side, and you are fetching it as a string... might want to consider having a fixed length grade to scan only once with "%s %d %d %d %d %d ..."
– arjayosma
Nov 14 '18 at 4:09
when the program iterates through your file, your very first fscanf successfully retrieves the course, then checks the succeeding values. so once your loop iterates again, then the fscanf will check on the digit side, and you are fetching it as a string... might want to consider having a fixed length grade to scan only once with "%s %d %d %d %d %d ..."
– arjayosma
Nov 14 '18 at 4:09
1
1
The best thing to do is see one of the teacher's assistants. You need a lot more help than can be provided in a stack overflow Q&A.
– user3386109
Nov 14 '18 at 4:14
The best thing to do is see one of the teacher's assistants. You need a lot more help than can be provided in a stack overflow Q&A.
– user3386109
Nov 14 '18 at 4:14
1
1
A hint - Take it line by line. For the first line you first scan the Name - put that in the courses array. Then scan the amount of grades. Put that in amount of grades array. Then run a loop for no of grades (scanned previously, say n). Scan n grades. Calculate the average. Put the average in the average array. Repeat entire thing 3 times for 3 lines (or until end of file)
– Rishikesh Raje
Nov 14 '18 at 4:24
A hint - Take it line by line. For the first line you first scan the Name - put that in the courses array. Then scan the amount of grades. Put that in amount of grades array. Then run a loop for no of grades (scanned previously, say n). Scan n grades. Calculate the average. Put the average in the average array. Repeat entire thing 3 times for 3 lines (or until end of file)
– Rishikesh Raje
Nov 14 '18 at 4:24
add a comment |
2 Answers
2
active
oldest
votes
You can solve this problem by reading the file line by line using fgets(),and extracting each word in line using strtok().strtok can separate line into words if we give delimiter as space.Below i am giving a code to extract courses and total_number of grades in my.txt to separate array. An unrefined Code written by me is given below.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
void print_word (char *str ,int i);
static char content[10][40];
char courses[10][20];
int total_num_grades[10];
int line_count =0 ;
void parse_word (char *str ,int line_num)
{
char *temp ;
int word_num = 0;
printf ("Splitting string "%s" into tokens:n",str);
temp = strtok (str," "); //taking first word of line
strcpy(courses[line_num] ,temp);
temp = strtok (NULL, " "); //taking second word of line
total_num_grades[line_num] = atoi(temp);
}
void print_result()
{
printf("courses in the text nn");
for(int i = 0; i <line_count ; i ++)
{
printf("%sn",courses[i]);
}
printf ("nnnumber of grade array nn");
for(int i = 0;i < line_count ;i ++)
{
printf("%dn",total_num_grades[i]);
}
}
int main () {
FILE *fp;
int len = 0,read = 0;
fp = fopen("my.txt", "r");
while ((fgets(content[line_count], 400, fp))) {
printf("%s", content[line_count]);
line_count ++;
}
for (int line_num = 0; line_num < line_count ; line_num++)
{
parse_word(&content[line_num][0],line_num);
}
print_result();
return(0);
}
strtok usage example
add a comment |
fscanf(, "%s", buffer)
reads a string until a whitespace and puts the result in the buffer.
First call fscanf(fp, "%s", courses);
will read Mathematics and store the word in courses array.
Second call fscanf(fp, "%s", courses);
will read 5 and store the character in courses array
You will need to convert characters to numbers, check for newlines, handle errors - what if an incoming character is not a digit, etc?
Your first call fscanf(fp, "%s", &courses[i]); gets a course name. Second iteration of your loop will give you "M1thematics" in the courses. You don't need [i] part. You need to change your loop. And what's that arbitrary 300 number?
Another hint: &courses[0] points to the start of the array, same as just courses. &courses[1] points to the second element in courses.
The rest is up to you.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292968%2fc-file-with-both-integer-and-string-division-problems%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can solve this problem by reading the file line by line using fgets(),and extracting each word in line using strtok().strtok can separate line into words if we give delimiter as space.Below i am giving a code to extract courses and total_number of grades in my.txt to separate array. An unrefined Code written by me is given below.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
void print_word (char *str ,int i);
static char content[10][40];
char courses[10][20];
int total_num_grades[10];
int line_count =0 ;
void parse_word (char *str ,int line_num)
{
char *temp ;
int word_num = 0;
printf ("Splitting string "%s" into tokens:n",str);
temp = strtok (str," "); //taking first word of line
strcpy(courses[line_num] ,temp);
temp = strtok (NULL, " "); //taking second word of line
total_num_grades[line_num] = atoi(temp);
}
void print_result()
{
printf("courses in the text nn");
for(int i = 0; i <line_count ; i ++)
{
printf("%sn",courses[i]);
}
printf ("nnnumber of grade array nn");
for(int i = 0;i < line_count ;i ++)
{
printf("%dn",total_num_grades[i]);
}
}
int main () {
FILE *fp;
int len = 0,read = 0;
fp = fopen("my.txt", "r");
while ((fgets(content[line_count], 400, fp))) {
printf("%s", content[line_count]);
line_count ++;
}
for (int line_num = 0; line_num < line_count ; line_num++)
{
parse_word(&content[line_num][0],line_num);
}
print_result();
return(0);
}
strtok usage example
add a comment |
You can solve this problem by reading the file line by line using fgets(),and extracting each word in line using strtok().strtok can separate line into words if we give delimiter as space.Below i am giving a code to extract courses and total_number of grades in my.txt to separate array. An unrefined Code written by me is given below.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
void print_word (char *str ,int i);
static char content[10][40];
char courses[10][20];
int total_num_grades[10];
int line_count =0 ;
void parse_word (char *str ,int line_num)
{
char *temp ;
int word_num = 0;
printf ("Splitting string "%s" into tokens:n",str);
temp = strtok (str," "); //taking first word of line
strcpy(courses[line_num] ,temp);
temp = strtok (NULL, " "); //taking second word of line
total_num_grades[line_num] = atoi(temp);
}
void print_result()
{
printf("courses in the text nn");
for(int i = 0; i <line_count ; i ++)
{
printf("%sn",courses[i]);
}
printf ("nnnumber of grade array nn");
for(int i = 0;i < line_count ;i ++)
{
printf("%dn",total_num_grades[i]);
}
}
int main () {
FILE *fp;
int len = 0,read = 0;
fp = fopen("my.txt", "r");
while ((fgets(content[line_count], 400, fp))) {
printf("%s", content[line_count]);
line_count ++;
}
for (int line_num = 0; line_num < line_count ; line_num++)
{
parse_word(&content[line_num][0],line_num);
}
print_result();
return(0);
}
strtok usage example
add a comment |
You can solve this problem by reading the file line by line using fgets(),and extracting each word in line using strtok().strtok can separate line into words if we give delimiter as space.Below i am giving a code to extract courses and total_number of grades in my.txt to separate array. An unrefined Code written by me is given below.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
void print_word (char *str ,int i);
static char content[10][40];
char courses[10][20];
int total_num_grades[10];
int line_count =0 ;
void parse_word (char *str ,int line_num)
{
char *temp ;
int word_num = 0;
printf ("Splitting string "%s" into tokens:n",str);
temp = strtok (str," "); //taking first word of line
strcpy(courses[line_num] ,temp);
temp = strtok (NULL, " "); //taking second word of line
total_num_grades[line_num] = atoi(temp);
}
void print_result()
{
printf("courses in the text nn");
for(int i = 0; i <line_count ; i ++)
{
printf("%sn",courses[i]);
}
printf ("nnnumber of grade array nn");
for(int i = 0;i < line_count ;i ++)
{
printf("%dn",total_num_grades[i]);
}
}
int main () {
FILE *fp;
int len = 0,read = 0;
fp = fopen("my.txt", "r");
while ((fgets(content[line_count], 400, fp))) {
printf("%s", content[line_count]);
line_count ++;
}
for (int line_num = 0; line_num < line_count ; line_num++)
{
parse_word(&content[line_num][0],line_num);
}
print_result();
return(0);
}
strtok usage example
You can solve this problem by reading the file line by line using fgets(),and extracting each word in line using strtok().strtok can separate line into words if we give delimiter as space.Below i am giving a code to extract courses and total_number of grades in my.txt to separate array. An unrefined Code written by me is given below.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
void print_word (char *str ,int i);
static char content[10][40];
char courses[10][20];
int total_num_grades[10];
int line_count =0 ;
void parse_word (char *str ,int line_num)
{
char *temp ;
int word_num = 0;
printf ("Splitting string "%s" into tokens:n",str);
temp = strtok (str," "); //taking first word of line
strcpy(courses[line_num] ,temp);
temp = strtok (NULL, " "); //taking second word of line
total_num_grades[line_num] = atoi(temp);
}
void print_result()
{
printf("courses in the text nn");
for(int i = 0; i <line_count ; i ++)
{
printf("%sn",courses[i]);
}
printf ("nnnumber of grade array nn");
for(int i = 0;i < line_count ;i ++)
{
printf("%dn",total_num_grades[i]);
}
}
int main () {
FILE *fp;
int len = 0,read = 0;
fp = fopen("my.txt", "r");
while ((fgets(content[line_count], 400, fp))) {
printf("%s", content[line_count]);
line_count ++;
}
for (int line_num = 0; line_num < line_count ; line_num++)
{
parse_word(&content[line_num][0],line_num);
}
print_result();
return(0);
}
strtok usage example
answered Nov 15 '18 at 11:58
coddygeek
609
609
add a comment |
add a comment |
fscanf(, "%s", buffer)
reads a string until a whitespace and puts the result in the buffer.
First call fscanf(fp, "%s", courses);
will read Mathematics and store the word in courses array.
Second call fscanf(fp, "%s", courses);
will read 5 and store the character in courses array
You will need to convert characters to numbers, check for newlines, handle errors - what if an incoming character is not a digit, etc?
Your first call fscanf(fp, "%s", &courses[i]); gets a course name. Second iteration of your loop will give you "M1thematics" in the courses. You don't need [i] part. You need to change your loop. And what's that arbitrary 300 number?
Another hint: &courses[0] points to the start of the array, same as just courses. &courses[1] points to the second element in courses.
The rest is up to you.
add a comment |
fscanf(, "%s", buffer)
reads a string until a whitespace and puts the result in the buffer.
First call fscanf(fp, "%s", courses);
will read Mathematics and store the word in courses array.
Second call fscanf(fp, "%s", courses);
will read 5 and store the character in courses array
You will need to convert characters to numbers, check for newlines, handle errors - what if an incoming character is not a digit, etc?
Your first call fscanf(fp, "%s", &courses[i]); gets a course name. Second iteration of your loop will give you "M1thematics" in the courses. You don't need [i] part. You need to change your loop. And what's that arbitrary 300 number?
Another hint: &courses[0] points to the start of the array, same as just courses. &courses[1] points to the second element in courses.
The rest is up to you.
add a comment |
fscanf(, "%s", buffer)
reads a string until a whitespace and puts the result in the buffer.
First call fscanf(fp, "%s", courses);
will read Mathematics and store the word in courses array.
Second call fscanf(fp, "%s", courses);
will read 5 and store the character in courses array
You will need to convert characters to numbers, check for newlines, handle errors - what if an incoming character is not a digit, etc?
Your first call fscanf(fp, "%s", &courses[i]); gets a course name. Second iteration of your loop will give you "M1thematics" in the courses. You don't need [i] part. You need to change your loop. And what's that arbitrary 300 number?
Another hint: &courses[0] points to the start of the array, same as just courses. &courses[1] points to the second element in courses.
The rest is up to you.
fscanf(, "%s", buffer)
reads a string until a whitespace and puts the result in the buffer.
First call fscanf(fp, "%s", courses);
will read Mathematics and store the word in courses array.
Second call fscanf(fp, "%s", courses);
will read 5 and store the character in courses array
You will need to convert characters to numbers, check for newlines, handle errors - what if an incoming character is not a digit, etc?
Your first call fscanf(fp, "%s", &courses[i]); gets a course name. Second iteration of your loop will give you "M1thematics" in the courses. You don't need [i] part. You need to change your loop. And what's that arbitrary 300 number?
Another hint: &courses[0] points to the start of the array, same as just courses. &courses[1] points to the second element in courses.
The rest is up to you.
answered Nov 14 '18 at 4:31
dmitri
2,4281422
2,4281422
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292968%2fc-file-with-both-integer-and-string-division-problems%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
when the program iterates through your file, your very first fscanf successfully retrieves the course, then checks the succeeding values. so once your loop iterates again, then the fscanf will check on the digit side, and you are fetching it as a string... might want to consider having a fixed length grade to scan only once with "%s %d %d %d %d %d ..."
– arjayosma
Nov 14 '18 at 4:09
1
The best thing to do is see one of the teacher's assistants. You need a lot more help than can be provided in a stack overflow Q&A.
– user3386109
Nov 14 '18 at 4:14
1
A hint - Take it line by line. For the first line you first scan the Name - put that in the courses array. Then scan the amount of grades. Put that in amount of grades array. Then run a loop for no of grades (scanned previously, say n). Scan n grades. Calculate the average. Put the average in the average array. Repeat entire thing 3 times for 3 lines (or until end of file)
– Rishikesh Raje
Nov 14 '18 at 4:24