Oh , and yeah , as much as i want , i cannot use C++ , its a course in C.
Brutal low level C.
#include <stdio.h>
#include <stdlib.h>
int main()
{
//
FILE * pFile;
pFile = fopen ("file","r");
if (pFile==NULL)
printf("Error opening file: my.txt");
else
{
char studNum[8],first[10];
char second[10];
int final,midterm,quiz1,quiz2,quiz3;
double finalGrade;
char NumBuf [100];
int ch;
printf("Got here 1\n");
while((ch = (getc(pFile))) != EOF)
{
int lenght = 0;
while(ch!='\n' && ch!=EOF)
{
if(lenght <= 99)
{
NumBuf [lenght] = ch;
}
ch = (getc(pFile));
lenght++;
}
//If line is longer then 99 , omit it
if(lenght <= 99)
{
if(ch!=EOF)
printf("%s\n",NumBuf);
// BREAKING INTO SEPARATE STRINGS!!!
int pointer = 0;
int currentPointer = 0;
//STUDENT NUMBER!!!
while(NumBuf[pointer] != ' ')
{
if(isdigit(NumBuf[pointer]))
{
// printf("%i",pointer);
studNum[currentPointer]=NumBuf[pointer];
currentPointer++;
}
pointer++;
}
printf("Student Num %s \n",studNum);
//FIRST NAME!!!
currentPointer=0;
//Skip over empty spaces
while(NumBuf[pointer] ==' ')
{
pointer++;
}
while(NumBuf[pointer] != ' ')
{
first[currentPointer]=NumBuf[pointer];
currentPointer++;
pointer++;
}
printf("Student First : %s \n",first);
//SECOND NAME!!!
currentPointer=0;
//Skip over empty spaces
while(NumBuf[pointer] ==' ')
pointer++;
while(NumBuf[pointer] !=',')
{
printf("%i",pointer);
second[currentPointer]=NumBuf[pointer];
currentPointer++;
pointer++;
}
printf("Student Second : %.10s \n",second);
}
else
{
printf("MY SPOON IS TOO BIG\n");
}
}
printf("**** UP IS OVER HERE!!!\n");
}
fclose(pFile);
}