HELP HELP HELP

0 Suraj Gautam · August 26, 2015
Help me regarding this code
please please it's urgent

http://pastebin.com/4sUmdgjq



#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void add();
void read();
void edit();
int id;
char address[100];
char name[50];
int grade;
char stream[30];
void main()
{
    int num;
printf("1.Add Student details\n");
printf("2.Read Student details\n");
printf("3.Edit Student details\n");
printf("\n");
scanf("%d",&num);
switch(num)
{
    case 1: add();
            break;
    case 2: read();
            break;
    default: printf("No such option :) \n");
            break;
}
getch();
}
void add() {
    char choice='N';
    char word;
FILE *text;
text=fopen("add.txt","w");
do{
printf("\n");
printf("Enter 3 digit ID. No\n");
scanf("%d",&id);
printf("\n");
printf("Enter Name\n");
scanf("%s",name);
printf("\n");
printf("Enter address\n");
scanf("%s",address);
printf("\n");
printf("Enter grade\n");
scanf("%d",&grade);
printf("\n");
printf("Enter stream\n");
scanf("%s",stream);
printf("\n");
printf("You are done!!!!");
fprintf(text,"%d\t %s\t %s\t %d\t %s\t",id,name,address,grade,stream);
printf("\n");
printf("Enter Y for adding other details, else N\n");
scanf("% c",&word);
toupper(word);
fflush(stdin);}while(word!=choice);
fclose(text);
 getch();
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Franz Schmidt · August 26, 2015
Your last lines in your loop are a little messed up:

scanf(" %c", &word);
word = toupper(word);


First of all the space needs to be before the %c sign not between %c. (I know it doesn't make any sense to put a whithspace anywhere but just do it)

And touuper is a function which doesn't work with pointers. That means it's parameter is the value of the variable not the pointer to the variable (hope you allready learnd about pointers if not do so they are very usefull and very common in some programs)
And so the function needs a return value and this value needs to be asigned to variable or you lose the information whatever the function has done.

And a little tip on your way: Always if something does not work output something (I found your error because I did print out the variable word:D). It it's the variable or a nice "hello" after an if statement, whatever but you need to find the error or at least enclose the field of where the error could be and not just this and that does not work. 
0 Suraj Gautam · August 26, 2015
the loop is not working
0 Franz Schmidt · August 26, 2015
what exactly is your problem?
where are you stuck?
and what errors occur?
  • 1

C

107,193 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator