Hello to you all ,

Major problem in C , Files included

Summary of problem :
Program will not copy the feild "name" from struct "univ->std.name" properly. the rest of data is presented fairly.
do not touch function "output_university" .

Thank you ,

yotam , Israel .

Recommended Answers

All 4 Replies

In function input_university() I see where scanf() is reading the string, and univ->std[num_cells].name is getting allocated, but I don't see where it is copying buffer to univ->std[num_cells].name after allocation. Add this and it will probably work ok.

strcpy(univ->std[num_cells].name,buffer);

Apparently, I wasted my time :mad:
http://www.daniweb.com/techtalkforums/thread43435.html

Not only have you dropped the initialisation of univ in main(), but you've gone back to using fscanf to read the file.
Not only that, you're now using global variables like "temp", which get allocated on every iteration of the loop and never freed.
Don't forget the not using a temporary variable when calling realloc, nor the unnecessary casting of malloc and realloc.

Y'know what, if you're just going to ignore people, just say so - ok?

Apparently, I wasted my time :mad:
http://www.daniweb.com/techtalkforums/thread43435.html

Not only have you dropped the initialisation of univ in main(), but you've gone back to using fscanf to read the file.
Not only that, you're now using global variables like "temp", which get allocated on every iteration of the loop and never freed.
Don't forget the not using a temporary variable when calling realloc, nor the unnecessary casting of malloc and realloc.

Y'know what, if you're just going to ignore people, just say so - ok?

I guess i didnt see it - sorry mate :confused:

In function input_university() I see where scanf() is reading the string, and univ->std[num_cells].name is getting allocated, but I don't see where it is copying buffer to univ->std[num_cells].name after allocation. Add this and it will probably work ok.

strcpy(univ->std[num_cells].name,buffer);

I did just that . now it messes up another string - i'll figure it out
somehow , the thing is , we were never tought the subject BUFSIZ and
"sscanf" - so no offence there ;)
i got slapped on using it .... sorry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.