CFanatic

Go Back   CFanatic > Programming > C Programming

Join CFanatic Forum Now

the first time enter the "while loop" and the second no! Why? topic posted under C Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 08-31-2010, 04:00 AM
 
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
brack is on a distinguished road
| More
the first time enter the "while loop" and the second no! Why?

When i type first time 1 the printf appeared, but the second time i typed 1 there where no printf...can anyone help me?

Code:
#include
#include

struct Info{
char name[81];
int age;
char email[81];
int c;
};

int main(void){
FILE* infile;
struct Info info;

infile = fopen("my_file.txt","r+"); // pos: r, w, a, r+, w+, a+
if(infile ==NULL){
printf("File does not exist.\n");
exit(1);
}else{
printf("Please type 1 to see the statistics.\n");
printf("Please type 2 to add a new contact.\n");
printf("Plesase type 0 to exit.\n");
scanf("%d", &info.c);
while(1){


if(info.c == 1){
while(fscanf(infile,"%s %d %s", info.name, &info.age, info.email) != EOF){
printf("\tName: %s\n", info.name);
printf("\tAge: %d\n", info.age);
printf("\tE-mail: %s\n\n", info.email);
}
}else if(info.c == 2){
printf("New name:\n");
scanf("%s", info.name);
printf("New age:\n");
scanf("%d", &info.age);
printf("New e-mail:\n");
scanf("%s", info.email);
fprintf(infile,"%s %d %s", info.name, info.age, info.email);

fclose(infile);
infile = fopen("my_file.txt","r+");
}else{
exit(0);
}
printf("Please type 1 to see the statistics.\n");
printf("Please type 2 to add a new contact.\n");
printf("Plesase type 0 to exit.\n");
scanf("%d", &info.c);
}
}
fclose(infile);
return 0;
}
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a function 2 "PAUSE" and "RESUME" execution of a prg Ritesht93 C++ Programming 1 08-31-2010 03:46 AM
How many processes are created in a command that contains a "pipe" arsenal_fan Shell Scripting 0 08-28-2010 03:11 AM
problem in make file "urgently need solution" Rajkamal2013 C Programming 0 08-28-2010 03:11 AM
Error The text "*" is unexpected kaustubh.deo C++ Programming 0 09-30-2006 06:39 PM
why C# doesn't support "friend" relationship? Zeng C# Programming 4 09-12-2006 12:11 PM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 02:21 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board