Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
typedef QUALITY int;
#define PAIRENDLEN 2000
void getSSnumber(char *input,QUALITY *snpCount)
{
//char buff[BUFSIZ];
FILE *fp;
char *buf = (char *) calloc (PAIRENDLEN,sizeof(char));
//char buf[PAIRENDLEN];
for ( int i = 0; i < PAIRENDLEN; ++i ) buf[i] = '0';
if ( (fp = fopen(input,"r")) == 0 ){printf("open '%s' error in getSSnumber function\n",input); exit(0);}
int isKnownLen = 0;
QUALITY snpNumber = 0;
int i = 0;
while( feof(fp) == 0 )
{
if ( isKnownLen == 0 )
{
//char *buf = (char *) calloc (1,sizeof(char));
char c;
i = 0;
while( (c = fgetc(fp)) != '\n' )
{
//*(buf+i) = c;
//buf = (char *) realloc (buf,i+2);
//printf("%d\n",i+2);
++i;
}
++snpNumber;
//printf("ss %d\n",i);
//if ( snpNumber == 2 )
isKnownLen = 1;
}else
{
//char *buf;// = "aa";// = (char *) calloc (i,sizeof(char));
//if ( i > PAIRENDLEN ) { buf = (char *) realloc (buf,i); }
int j = i+1;
char tmp[j];tmp[0] = '0';
char *y = fgets(tmp,j,fp);
//printf("%s %d %d %s\n",y,snpNumber,strlen(tmp),tmp);
//buf[0] = '0';
int x = strlen(tmp);
if ( y && x >= 2 ) ++snpNumber;
//++snpNumber;
}
}
fclose(fp);
snpCount[0] = snpNumber;
snpCount[1] = i;
//printf("%ld %d\n",snpNumber,i);
}
int main(int argc,char **argv)
{
int e[2];
getSSnumber(argv[1],e);
printf("total line number:%d total col number:%d\n",e[0],e[1]);
return 0;
}
Is there any bugs in my codes?
Is there more simple codes to get total line and column number?
my inputfile is :
Code:
AAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAA
.........