C problen with Files

Reply

Join Date: Jan 2006
Posts: 38
Reputation: YoTaMiX is an unknown quantity at this point 
Solved Threads: 0
YoTaMiX YoTaMiX is offline Offline
Light Poster

C problen with Files

 
0
  #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)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 16,574
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1612
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: C problen with Files

 
0
  #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.
  1. strcpy(univ->std[num_cells].name,buffer);
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 6,584
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 848
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: C problen with Files

 
0
  #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 Quick reply to this message  
Join Date: Jan 2006
Posts: 38
Reputation: YoTaMiX is an unknown quantity at this point 
Solved Threads: 0
YoTaMiX YoTaMiX is offline Offline
Light Poster

Re: C problen with Files

 
0
  #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 Quick reply to this message  
Join Date: Jan 2006
Posts: 38
Reputation: YoTaMiX is an unknown quantity at this point 
Solved Threads: 0
YoTaMiX YoTaMiX is offline Offline
Light Poster

Re: C problen with Files

 
0
  #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.
  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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 968 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC