I think there are errors in the C intermidiate coarse | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I think there are errors in the C intermidiate coarse

https://www.sololearn.com/learn/courses/c-intermediate/tiy/974156312?returnUrl=/learn/courses/c-intermediate/lesson/962866126?p=3 ...................................................... Working With Files one of several errors ...................................................... #include <stdio.h> int main() { FILE *fptr; int c, stock; char buffer[200], item[10]; float price; /* myfile.txt: Inventory\n100 Widget 0.29\nEnd of List */ fptr = fopen("myfile.txt", "r"); fgets(buffer, 20, fptr); /* read a line */ printf("%s\n", buffer); fscanf(fptr, "%d%s%f", &stock, item, &price); /* read data */ printf("%d %s %4.2f\n", stock, item, price); while ((c = getc(fptr)) != EOF) /* read the rest of the file */ printf("%c", c); fclose(fptr); return 0; } ........................................................... timeout: the monitored command dumped core ./Playground/runner.sh: line 110: 12 Segmentation fault timeout "$runtime" "$output" - < "/usercode/inputFile"

20th May 2023, 3:39 AM
Rick Shiffman
Rick Shiffman - avatar
7 Answers
+ 6
Please send this information to info@sololearn.com
20th May 2023, 5:55 AM
JaScript
JaScript - avatar
+ 5
Inform to info@sololearn.com
20th May 2023, 8:43 AM
Alhaaz
Alhaaz - avatar
+ 3
I have already sent this to info@sololearn.con
20th May 2023, 12:50 PM
Rick Shiffman
Rick Shiffman - avatar
+ 3
Rick Shiffman then wait for their reply
20th May 2023, 3:08 PM
Hasnain [ACTIVE CHALLENGER]
Hasnain [ACTIVE CHALLENGER] - avatar
+ 1
You're right, inside the fscanf() function it should be "&item", not "item". This is what gives the segmentation failure.
20th May 2023, 10:47 PM
Евгений
Евгений - avatar
+ 1
The funny thing is that the _old_ C course has exactly the same code with this error. :)
20th May 2023, 10:53 PM
Евгений
Евгений - avatar
+ 1
The point I was realy making was this code was an exmple given in the lesson. It makes sense that &item would solve the problem Although item is a string and doesn't item point to the 1st character? Without the need for the &
21st May 2023, 2:48 PM
Rick Shiffman
Rick Shiffman - avatar