|
-
December 17th, 2001, 08:10 AM
#1
C programming!!!
I need to know how to print to data files.
I know there's fprintf and fputs but not sure how to read it back in for a report display
here is my code so far...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Menu();
void Create();
void Add();
void Edit();
void Delete();
void DisplayS();
void DisplayC();
int main()
{
Menu();
return 0;
}
void Menu()
{
int choice = 0;
while (choice != 7)
{
system("cls");
printf("\nWELCOME TO GRADE MASTER !");
printf("\n*****************************");
printf("\n* *");
printf("\n* 1. CREATE STUDENT FILE *");
printf("\n* *");
printf("\n* 2. ADD STUDENT FILE *");
printf("\n* *");
printf("\n* 3. EDIT STUDENT FILE *");
printf("\n* *");
printf("\n* 4. DELETE STUDENT FILE *");
printf("\n* *");
printf("\n* 5. DISPLAY STUDENT DATA *");
printf("\n* *");
printf("\n* 6. DISPLAY CLASS DATA *");
printf("\n* *");
printf("\n* 7. END PROGRAM *");
printf("\n* *");
printf("\n*****************************");
printf("\nRun which option ( 1 - 7 ) ?");
scanf("%d", &choice);
fflush(stdin);
switch (choice)
{
case 1: Create(); break;
case 2: Add(); break;
case 3: Edit(); break;
case 4: Delete(); break;
case 5: DisplayS(); break;
case 6: DisplayC(); break;
case 7: break;
}
}
}
void Create()
{
int pauser;
FILE *ptr_file;
ptr_file = fopen("STUDENT.DAT", "w");
fclose(ptr_file);
printf("\nFile STUDENT.DAT has success-\n");
printf("fully been created and is now\n");
printf("ready for student/class data. ");
for (pauser = 0; pauser < 150000000; pauser++)
{ // pause program so user can read message
}
}
void Add()
{
char stuName[30] = "\n";
// int moreG;
int moreS = 0;
// int grade;
FILE *ptr_file;
ptr_file = fopen("STUDENT.DAT", "a+");
fseek(ptr_file, 0L, SEEK_SET); // set pointer to file beginning
while (moreS != 2)
{
printf("Enter student's name: ");
scanf("%s%s", &stuName);
fflush(stdin);
fprintf(ptr_file, "%s %s¶", stuName);
printf("More students 1=y/2=n ?");
scanf("%d", &moreS);
}
fclose(ptr_file);
/*
moreG = 0;
grade = 0;
while (moreG != 2);
{
grade++;
printf("Enter the student's grade #%d: ", grade);
scanf("%s", &string);
fflush(stdin);
fprintf(ptr_file, "%s%s%c", string, '\n');
printf("Enter the code no. for this grade\n", grade);
printf("(1=project grade, 2=exam grade): ");
scanf("%s", &string);
fflush(stdin);
fprintf(ptr_file, "%s%s%c", string, '\n');
printf("Enter more grades (1=yes 2=no)?");
scanf("%d", &moreG);
fflush(stdin);
}
printf("Enter more student records (1=yes 2=no)?");
scanf("%d", &moreS);
fflush(stdin);
*/
}
void Edit()
{
printf("got it");
system("pause");
}
void Delete()
{
printf("got it");
system("pause");
}
void DisplayS()
{
printf("got it");
system("pause");
}
void DisplayC()
{
char string2[30];
FILE *ptr_file;
ptr_file = fopen("STUDENT.DAT", "r+");
char string[30] = "";
fseek(ptr_file, 0L, SEEK_SET); // set pointer to file beginning
fscanf(ptr_file, "%s %s", &string2); // read first two strings from file
printf("%s %s", string2); // display strings
system("pause");
fclose(ptr_file);
}
------------EViLSEED
Hackers are impervious. Resistant is futile.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|