c - Reading number of commas in a string not working in Visual Studio 2010 -


i wrote simple c program counting number of commas in string. simple console c application done in visual studio 2010 professional.

the string read text file answer wrong.

after spending many hours trying , that, posting here, hoping can me out. pasting code here , sample line text file. please take @ it.

#include <stdio.h> #include <stdlib.h> #include <malloc.h>  int main() { char *myline; file *outputf; int line_len=4800; int ncomas=0; int i=0;     int coma_count=0;              outputf = fopen("c:\\tmp\\tmp.csv","r+");             if (outputf == null)             {                 printf("couldn't open csv file writing.\n");                             }             else             {                                                                myline=(char *)calloc(1,line_len);                 while(fgets(myline,line_len,outputf) != null)                 {                     ncomas=0;                     for(i=0;i<line_len;i++)                     {                         if(myline[i]==',')                         {                             ncomas++;                         }                     }                     printf("\nno of commas %d\n",ncomas);                 }                                fclose(outputf);             }             return; } 

here sample line file. actual count 159 getting 216.

-1, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -