Advertisement

[x]
Attachment Details

sscanf and while loops

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1
Ok, If there are 5 lines to the file this needs to read in, why will scanf only scan the first line 5 times into the structure array, and printf will print the whole file? I put a for loop at the end to show what it really scanned in. I also included the output at the end

file *in;
char string [256];
in = fopen(filename, "r");


 while (fgets(string,sizeof(string),in) != NULL){
   sscanf(string,"%d %s %d %d %d %d %[^\0]",&list[1].id,list[1].name, &list[1].\
north, &list[1].west, &list[1].south, &list[1].east, list[1].description);
  print f("%d %s %d %d %d %d %s\n", list[i].id, list[i].name, list[i].north, li\
st[i].west, list[i].south, list[i].east, list[i].description);      }

 int j;
  for(j=0; j<5; j++){
   printf("%d %s %d %d %d %d %s\n", list[j].id, list[j].name, list[j].north, li\
st[j].west, list[j].south, list[j].east, list[j].description);
   }





sneffels> a.out notes.txt
0 Kitchen -1 -1 -1 1 The place where all hang out for food and gossip. Dare ye who lingers too long!
1 Diner 2 0 -1 -1 To dine and wine and entertain. Dress code strictly enforced!
2 Parlor 3 -1 1 4 Parlor
3 Pit -1 -1 -1 -1 Pit of despair. There is NO excape!
4 Hallway -1 2 -1 5 Hallway passage from one room to another and nothing more.
5 Bedroom -1 4 -1 -1 Bedroom
5 Bedroom -1 4 -1 -1 Bedroom
0  1177975792 32767 1177976328 32767
2050  1177977160 32767 0 0
0  0 0 0 0
0  1197276 0 24876 0
Welcome to the CS157 Dungeon.
*** Don't get eaten by a grue! ***
Type c for current room, n for north, w for west, s for south, e for east
>
Related Solutions
Related Solutions
 
Loading Advertisement...
 

Rank: Sage

Expert Comment by sunnycoder:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 

Rank: Sage

Accepted Solution by sunnycoder:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 

Rank: Master

Expert Comment by josgood:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 

Rank: Master

Expert Comment by josgood:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Author Comment by jeffiepoo:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Author Comment by jeffiepoo:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
Loading Advertisement...
20080924-EE-VQP-40 / EE_QW_2_20070628