I'm sorry for that, i wrote the flow of the program just to explain my program clearly... The main point of my previous thread was i don't really understand algorithm to do checksum..i read on other forum there were quite a few ways to do so. But still i found it hard to understand and don't know which one to choose.
Before i have to do checksum i've got to validate type of data and for each line in srecord first. Now my problem is regarding to validate each line. The problem with my code is it did not displayed all the lines in srecord which is almost 600 lines. instead of it displayed only line 1 - 9 and no error produce. I did not set any range for line displayed, so i wonder where the hack is wrong untill it displayed such way... If you don't mind could you help me to understand which part is wrong in my code.
ex:line 1, st[0] is start code must equal to 'S'
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int baris = 1;
int flag1, flag2 = 0 ;
int main(void)
{
FILE *f;
char s[20000];
f=fopen("ts820.mot","r");
if (!f)
return 1;
while (fgets(s,20000,f)!=NULL)
{
validateStrCd(s, baris);
validateRecty(s, baris);
printf("%s",s);
if ((flag1==1) || (flag2==1))
{
break; /*Or continue if you want to return to the input again*/
}
baris++;
fclose(f);
}
return 0;
}
int validateStrCd(char *st, int line)
{
if(st[0]=='S')
{
printf("Valid start code at line %d\n", line);
printf("%c\n", st[0]);
}
else
{
printf("Invalid start code at line %d\n", line);
printf("%c\n", st[0]);
flag1 = 1;
}
return 0;
}
int validateRecty(char *str, int line)
{
if (str[1] < '0' || str[1] > '9')
{
printf("Invalid start code at line %d\n", line);
printf("%c\n", str[1]);
flag2 = 1;
}
return 0;
}