Why does this program prints many times the red point?
thanks in advance...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct myInfo{
char my_name[81];
char my_phone[81];
char my_street[81];
char my_email[81];
};
struct Info{
char name[81];
char phone[81];
char street[81];
char email[81];
};
// It prints name, phone, address, and e-mail.
void print(struct Info info){
printf("Diagnostic.\n\n");
}
int main(void){
int choice;
char buf[6];
FILE *infile;
struct Info info;
struct myInfo myinfo;
print(info);
// Opening the file.
infile = fopen("file.txt","r+");
// Check if the file exist.
if(infile==NULL){
printf("Error :(\n");
exit(1);
}
// Reading the file. Read: name, phone, address and e-mail. It read and prints, reads prints, reads prints...
while(fscanf(infile,"%s %s %s %s", info.name, info.phone, info.street, info.email) != EOF){
print(info);
}
printf("If you want to put a new contact please type: 1\n");
printf("To exit please type: 0\n");
scanf("%d", &choice);
if(choice==1){ //Giving info for a new contact.
printf("Please type your name:");
scanf("%s", myinfo.my_name);
printf("Please type your phone:");
scanf("%s", myinfo.my_phone);
printf("Please type your street:");
scanf("%s", myinfo.my_street);
printf("Please type your e-mail:");
scanf("%s", myinfo.my_email);
//These are the info the user typed.
printf("Your name is: %s\n", myinfo.my_name);
printf("Your phone is: %s\n", myinfo.my_phone);
printf("Your name is: %s\n", myinfo.my_street);
printf("Your name is: %s\n", myinfo.my_email);
//Puting them into the file, using fprintf.
fprintf(infile,"%s %s %s %s", myinfo.my_name, myinfo.my_phone, myinfo.my_street, myinfo.my_email);
}else if(choice==0){
printf("Are you sure yes/no?\n");
scanf("%s", buf);
if(buf=="yes"){
exit(1);
}else{
printf("I was hoping to come back!\n");
}
}
fclose(infile);
return 0;
}