•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,884 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,034 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 6192 | Replies: 50
![]() |
It would really help readability if you'd indent more. 1 space is hard to follow -- it's too much like none. Generally the recommendation is 3-4 spaces. Not a hard and fast rule, but a general rule. Readability is the key.
•
•
Join Date: Aug 2006
Posts: 24
Reputation:
Rep Power: 3
Solved Threads: 0
I've made a new coding here. But it seems to be a little error.
The two questions seems to come out together.
the output
Enter his/her name: <---- The problem
Enter his/her birthday:<--- is here
Enter his/her handphone:
Enter his/her Address:
Enter his/her Occupation:
The two questions seems to come out together.
the output
Enter his/her name: <---- The problem
Enter his/her birthday:<--- is here
Enter his/her handphone:
Enter his/her Address:
Enter his/her Occupation:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define NAMES 80
#define BIRTHDAY 30
#define HANDPHONE 15
#define ADDRESS 120
#define OCCUPATION 50
#define SIZE 200
void Add();
void Del();
void Search();
void Edit();
void List();
void Exit();
char info[SIZE];
struct contactbook
{
char names [NAMES];
char birthday [BIRTHDAY];
char hp [HANDPHONE];
char address [ADDRESS];
char occupation [OCCUPATION];
char Target [SIZE];
}
contactbook;
FILE *Contactbook;
FILE *temp;
int main()
{
int option;
system("clear");
printf("\n WELCOME TO BRONTOK-X SIMPLE CONTACT BOOK\n");
printf("\n This program enables you to:\n");
printf("\n ADD, DELETE, EDIT, SEARCH, and LIST\n");
printf("\n your contact info =D\n\n");
printf("\n To start running this program, you have to choose an option from 1 to 6\n");
printf("\n 1: Adding Contact Info\n");
printf(" 2: Delete Your Contact Info\n");
printf(" 3: Search Your Contact Info\n");
printf(" 4: Edit Your Contact Info\n");
printf(" 5: List Down All Your Contact Info\n");
printf(" 6: Exit This Program\n\n");
printf(" Please Enter Your Choice: ");
scanf("%d", &option);
switch(option)
{
case 1:
{
system("clear");
Add();
break;
}
case 2:
{
system("clear");
Del();
break;
}
case 3:
{
system("clear");
Search();
break;
}
case 4:
{
system("clear");
Edit();
break;
}
case 5:
{
system("clear");
List();
break;
}
case 6:
{
system("clear");
Exit();
break;
}
default:
{
system("clear");
printf("Invalid Input");
break;
}
}
}
void Add()
{
Contactbook = fopen("Contactbook.txt","a+");
printf("Enter his/her Name:\n");
fflush(stdin);
fgets(contactbook.names, sizeof contactbook.names, stdin);
printf("Enter his/her Birthday:\n");
fflush(stdin);
fgets(contactbook.birthday, sizeof contactbook.birthday, stdin);
printf("Enter his/her Handphone No:\n");
fflush(stdin);
fgets(contactbook.hp, sizeof contactbook.hp, stdin);
printf("Enter his/her Address:\n");
fflush(stdin);
fgets(contactbook.address, sizeof contactbook.address, stdin);
printf("Enter his/her Occupation\n");
fflush(stdin);
fgets(contactbook.occupation, sizeof contactbook.occupation, stdin);
fprintf(Contactbook, "%s %s %s %s %s\n", contactbook.names,contactbook.birthday, contactbook.hp, contactbook.address, contactbook.occupation);
fflush(stdin);
fclose(Contactbook);
main();
}
void Del()
{
main();
}
void Search()
{
main();
}
void Edit()
{
main();
}
void List()
{
main();
}
void Exit()
{
system("clear");
}
Take another look at the "user input" link I posted.
Don't use
Don't call
Don't use
fflush(stdin).Don't call
main recursively. •
•
Join Date: Aug 2006
Posts: 24
Reputation:
Rep Power: 3
Solved Threads: 0
•
•
•
•
Take another look at the "user input" link I posted.
Don't usefflush(stdin).
Don't callmainrecursively.
I've take another look at the "user input" but still didn't get what you mean. Removing fflush(stdin) will still give me the same result.
The weird thing is, this code worked nicely in windows but using knoppix it seems to be a little bit screw with the add() function, imean as i said previously the tqo question seems don't want to be separated. That's the only problem i have for now.One more thing, if i can't call main() recursively, can u suggest me any other way to call the main just after finish other function.
•
•
Join Date: Jul 2006
Posts: 65
Reputation:
Rep Power: 4
Solved Threads: 14
> One more thing, if i can't call main() recursively, can u suggest me any other way to call the main just after finish other function.
You don't need to call main; when your function finishes, it returns the calling function. If you need the code to repeat, use a loop within main.
>The weird thing is, this code worked nicely in windows but using knoppix it seems to be a little bit screw with the add()
Because what you were doing was undefined. It might work, or it might blow up your computer. Maybe this will help.
You don't need to call main; when your function finishes, it returns the calling function. If you need the code to repeat, use a loop within main.
>The weird thing is, this code worked nicely in windows but using knoppix it seems to be a little bit screw with the add()
Because what you were doing was undefined. It might work, or it might blow up your computer. Maybe this will help.
Last edited by GloriousEremite : Aug 29th, 2006 at 11:27 pm.
"What are the roots that clutch, what branches grow
out of this stony rubbish?"
out of this stony rubbish?"
•
•
Join Date: Aug 2006
Posts: 24
Reputation:
Rep Power: 3
Solved Threads: 0
•
•
•
•
> One more thing, if i can't call main() recursively, can u suggest me any other way to call the main just after finish other function.
You don't need to call main; when your function finishes, it returns the calling function. If you need the code to repeat, use a loop within main.
>The weird thing is, this code worked nicely in windows but using knoppix it seems to be a little bit screw with the add()
Because what you were doing was undefined. It might work, or it might blow up your computer. Maybe this will help.
hmmm........can u pls explain it in details bcoz i'm still newbie in C programming. and this is group work, so have to do some research on the topic. I still can't imagine how to use loop to recall a function. examples plz if u don't mind.
•
•
•
•
hmmm........can u pls explain it in details bcoz i'm still newbie in C programming. and this is group work, so have to do some research on the topic. I still can't imagine how to use loop to recall a function. examples plz if u don't mind.
Lerner already showed you here, about 6 posts ago.
Also, don't PM members to personally solve your problem for you. Ask questions here, read what they say, and attempt what they tell you.
Last edited by WaltP : Aug 30th, 2006 at 1:14 am.
•
•
Join Date: Aug 2006
Posts: 24
Reputation:
Rep Power: 3
Solved Threads: 0
•
•
•
•
Lerner already showed you here, about 6 posts ago.
Also, don't PM members to personally solve your problem for you. Ask questions here, read what they say, and attempt what they tell you.
i already tried the code that was given by Lerner, but it seems to be have many error that i can't figure out . "parse error before "contactbook" " and other two more error which i don't remember. And i don't used and don't understand getch() function.
Sorry for my bad manner in using PM.
•
•
•
•
i already tried the code that was given by Lerner, but it seems to be have many error that i can't figure out . "parse error before "contactbook" " and other two more error which i don't remember. And i don't used and don't understand getch() function.
You don't need to compile and run his code. Look at what he did in
main() to set up a loop. Then you can stop calling main() from your functions. ![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
api apple asm assembly x86 programming hla demo blogger blogging c c++ ccna cocoa code coding competition compiler compilers computer debugging developer development errors evaluation framework gdata google high-performance innovation java languages linerider mcse microsystems networking news next object online open oriented planning platform practices programming python rss software step steps sun tools tutorials xml
- Shell Programming (Shell Scripting)
- Programming (C++)
- Where to get started with Web Programming (IT Careers and Business)
- Programming in Linux? (*nix Software)
- Help Me on Symbian(OS) Programming with c++ (C++)
- Good books on Shell Programming/Perl (Perl)
- Efficient Programming (Computer Science and Software Design)
- New To Programming = ME!! (C++)
Other Threads in the C Forum
- Previous Thread: realy fresh to C
- Next Thread: Connecting database using C


Linear Mode