![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 2
| Some help with a program. I need some help with a program I am writing: Write a program that will allow the user to enter the results of TEST1 for (Computing Systems and Programming) subject and store them in a data file named TEST1.txt. The data file “TEST1.txt” should have the following format: Code: Matric No. Name Marks Code: #include <stdio.h>
#include <stdlib.h>
//#include <cstring.h>
#define FILENAME "data.txt"
int main (void)
{
int num;
printf ("How many students would you like to place record for?\n");
scanf ("%d", &num);
char name;
int matric;
double marks;
FILE *datatab;
datatab = fopen (FILENAME,"a");
if (datatab == NULL)
printf ("Error opening File\n");
else
{
printf ("num = %d\n",num);
int i = 0;
while (i<num)
{
printf ("i = %d\n",i);
printf ("Please Enter name(Less than 50 Characters:\n");
fflush(stdin);
scanf("%s", &name);
fflush(stdin);
printf ("Please Enter Matric Number:\n");
scanf("%d", &matric);
fflush(stdin);
printf ("Please Enter Marks Obtained (via Cheating or otherwise):\n");
scanf("%f", &marks);
fflush(stdin);
fprintf (datatab,"%d %s %.2f\n", matric,name,marks);
// fflush(stdin);
i++;
}
fclose(datatab);
}
system("pause");
return 0;
}
Matric number ex: 0987674 (I want the zero to be displayed) Name ex: Anything (Just the first name would be enough). Marks ex: 67.89 (Maximum of 2 digit decimal) |
| K12 is offline | |
| | #2 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,260
| Try compiling with warnings on. That'd point you in the right direction. 1. fflush wasn't designed to work on input streams. 2. name is only a single character. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #3 |
| Registered User Join Date: Oct 2009
Posts: 2
| How do I enable warnings in Dev C++? |
| K12 is offline | |
![]() |
| Tags |
| data, file, marks, students, text |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Issue with program that's calling a function and has a loop | tigerfansince84 | C++ Programming | 9 | 11-12-2008 01:38 PM |
| Need help with a program, theres something in it for you | engstudent363 | C Programming | 1 | 02-29-2008 01:41 PM |
| This is a simple program.. Help me please I think it has an error.. | lesrhac03 | C Programming | 4 | 02-21-2008 10:39 AM |
| My program, anyhelp | @licomb | C Programming | 14 | 08-14-2001 10:04 PM |