RSS Forums RSS
Please support our C advertiser: Programming Forums
Views: 736 | Replies: 4
Reply
Join Date: Jan 2006
Location: Israel
Posts: 37
Reputation: YoTaMiX is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
YoTaMiX YoTaMiX is offline Offline
Light Poster

Help C problen with Files

  #1  
Apr 23rd, 2006
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, 5 views)
File Type: txt input.txt (93 Bytes, 3 views)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,639
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 986
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: C problen with Files

  #2  
Apr 23rd, 2006
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);
Reply With Quote  
Join Date: Dec 2005
Posts: 3,904
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 444
Colleague
Salem's Avatar
Salem Salem is offline Offline
Senior Poster

Re: C problen with Files

  #3  
Apr 23rd, 2006
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?
Reply With Quote  
Join Date: Jan 2006
Location: Israel
Posts: 37
Reputation: YoTaMiX is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
YoTaMiX YoTaMiX is offline Offline
Light Poster

Re: C problen with Files

  #4  
Apr 23rd, 2006
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
Reply With Quote  
Join Date: Jan 2006
Location: Israel
Posts: 37
Reputation: YoTaMiX is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
YoTaMiX YoTaMiX is offline Offline
Light Poster

Re: C problen with Files

  #5  
Apr 23rd, 2006
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.
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:47 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC