943,910 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1056
  • C RSS
Apr 23rd, 2006
0

C problen with Files

Expand Post »
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 .
Attached Files
File Type: c TEST2.C (3.9 KB, 8 views)
File Type: txt input.txt (93 Bytes, 7 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
YoTaMiX is offline Offline
38 posts
since Jan 2006
Apr 23rd, 2006
0

Re: C problen with Files

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.
  1. strcpy(univ->std[num_cells].name,buffer);
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Apr 23rd, 2006
0

Re: C problen with Files

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?
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Apr 23rd, 2006
0

Re: C problen with Files

Quote originally posted by Salem ...
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
Reputation Points: 10
Solved Threads: 0
Light Poster
YoTaMiX is offline Offline
38 posts
since Jan 2006
Apr 23rd, 2006
0

Re: C problen with Files

Quote originally posted by Ancient Dragon ...
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.
  1. 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
Reputation Points: 10
Solved Threads: 0
Light Poster
YoTaMiX is offline Offline
38 posts
since Jan 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Help me. binary seach tree
Next Thread in C Forum Timeline: deleting operation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC