Home > Back-end >  Problem for help why don't I call the input () function? Pleaded with his eldest brother this p
Problem for help why don't I call the input () function? Pleaded with his eldest brother this p

Time:01-16

#include
#include
#include
# define N 2
Typedef struct
{
Char name [10].
Char num [10].
Float c;
} stu.
Void input ();
Void menu ();
Int main ()
{
FILE *fp;
If ((fp=fopen (" d: \ \ work \ \ C grade book \ \ C language TXT ", "wb"))==NULL)
{
Printf (" \ nopen file error ");
getchar();
The exit (1);
}
char ch;
While (1)
{
menu();//display menu
ch=getchar();//select menu
If (ch=='0')
break;
The switch (ch)//judgment feature
{
Case '1' : input (); break;
}
}
Printf (" \ n \ n \ n \ t \ t \ \ t tWelcome to use, Goodbye! \ 02! \n");
return 0;
}
Void input ()
{
FILE *fp;
int i=0;
Stu xs [N]./* define a structure variable to read out data from file */
If ((fp=fopen (" d: \ \ work \ \ C grade book \ \ C. TXT ", "wb"))==NULL)
{
Printf (" \ nopen file error ");
getchar();
The exit (1);
Printf (" \ n input format: name, student id C \ n ");
Printf (" when input name for end to end entry \ n ");
While (1)
{
The scanf (" % s ", & amp; Xs [I] name);
If (STRCMP (xs [I]. The name, "end")==0) break;//to determine whether a name for the LAST and judge by string
The scanf (" % s % f ", & amp; Xs [I]. Num, & amp; Xs [I]. C);
Fprintf (fp, "% s % s % f", xs [I]. C, xs [I] num, xs [I] c);
i++;//will result information written to the file
}
fclose(fp);
}
}
Void menu ()
{
system("cls");//clear screen
Printf (" \ n \ n \ n \ n \ t \ \ t t * * * * * * * * * c record thin * * * * * * * * * * * \ n ");
Printf (" \ t \ \ t t |==========================================| \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 1. Input information * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 2. The query result * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 3. Modify the information * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 4. Add the student * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 5. Delete the result * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 6. Display result * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 7. Statistics * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 0. Out of * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t |==========================================| \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | \ n ");
Printf (" \ n \ n \ t \ \ t t please choose the corresponding function & lt; The input number & gt; : ");
}

CodePudding user response:

 
//input informationVoid input () {
FILE *fp;
Stu xs./* define a structure variable to read out data from file */
If ((fp=fopen (" d: \ \ work \ \ C grade book \ \ C language TXT ", "wb"))==NULL) {
Printf (" \ nopen file error ");
getchar();
The exit (1);
}
Printf (" \ n input format: name, student id C \ n ");
Printf (" when input name for end to end entry \ n ");
While (1) {
The scanf (" % s ", xs. Name);
If (STRCMP (xs. The name, the "end")==0) break;//to determine whether a name for the LAST and judge by string
The scanf (" % s % f ", & amp; Xs. Num, & amp; Xs. C);
Fprintf (fp, "% s % s % f", xs. The name, xs, num, xs, c);//will result information written to the file
}
fclose(fp);
}

CodePudding user response:

 # include & lt; stdio.h> 
#include
#include

# define N 2

Typedef struct
{
Char name [10].
Char num [10].
Float c;
} stu.

Void input ();
Void menu ();

Int main ()
{
FILE *fp;
If ((fp=fopen (" d: \ \ work \ \ C grade book \ \ C language TXT ", "wb"))==NULL)
{
Printf (" \ nopen file error ");
getchar();
The exit (1);
}
//char ch;
int ch;
While (1)
{
menu();//display menu
//ch=getchar ();//select menu
The scanf (" % d ", & amp; Ch);
//if (ch=='0')
If (ch==0)
break;
//printf (" \ n ch=% d ", ch);
The switch (ch)//judgment feature
{
//case '1' : input (); break;
Case 1: input (); break;
}
}
Printf (" \ n \ n \ n \ t \ t \ \ t tWelcome to use, Goodbye! \ 02! \n");
return 0;
}
Void input ()
{
FILE *fp;
int i=0;
//puts (" helloworld! \n");
Stu xs [N]./* define a structure variable to read out data from file */
If ((fp=fopen (" d: \ \ work \ \ C grade book \ \ C. TXT ", "wb"))==NULL)
{
Printf (" \ nopen file error ");
getchar();
The exit (1);
}
Printf (" \ n input format: name, student id C \ n ");
Printf (" when input name for end to end entry \ n ");
While (1)
{
//the scanf (" % s ", & amp; Xs [I] name);
The scanf (" % s ", xs [I] name);
If (STRCMP (xs [I]. The name, "end")==0) break;//to determine whether a name for the LAST and judge by string
//the scanf (" % s % f ", & amp; Xs [I]. Num, & amp; Xs [I]. C);
The scanf (" % s % f ", xs [I] num, & amp; Xs [I]. C);
//fprintf (fp, "% s % s % f", xs [I]. C, xs [I] num, xs [I] c);
Fprintf (fp, "% s % s % f", xs [I]. Name, xs [I] num, xs [I] c);
i++;//will result information written to the file
}
fclose(fp);
//}
}
Void menu ()
{
system("cls");//clear screen
Printf (" \ n \ n \ n \ n \ t \ \ t t * * * * * * * * * c record thin * * * * * * * * * * * \ n ");
Printf (" \ t \ \ t t |==========================================| \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 1. Input information * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 2. The query result * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 3. Modify the information * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 4. Add the student * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 5. Delete the result * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 6. Display result * * * * * * * * * * * * * * * | \ n "); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related