Code:#include<stdio.h> void main() { char temp[10]; FILE *input1 = NULL; FILE *input2 = NULL; unsigned char buffer[100], lTempData[7][20]; char *lPtr = NULL; int i =0; input1 = fopen("/u/n073313/vijay/File.txt", "rb"); fread(buffer, 1,100, input1); { printf("First line %s\n",buffer); lPtr = strtok(buffer, ","); strncpy(lTempData[i], lPtr, strlen(lPtr)); while (lPtr != NULL) { i++; strncpy(lTempData[i], lPtr, strlen(lPtr)); } for (int j =0; j< 7 ; j++) printf("Values %s\n", lTempData[i]); int a = atol(lTempData[5]); int b = atol(lTempData[6]); int c = a+b; printf("Values %d %d result %d\n", a, b, c); sprintf(temp, "%d", c); input2 = fopen("File2.txt", "r"); fwrite(c, 1, 10, input2); fclose(input1); fclose(input2); } }
The i/p txt file is like this
939,MUM,ord,396,2,3.0,4.0
100,bom,nru,1009,10,4.0,6.0
and i want to add 3.0+4.0=7.0
i.e
First i want to read the txt file add last two columns writing it into another txt I written the code and i run the code i am getting
------------------------------------
939,MUM,ord,396,2,3.0,4.0
100,bom,nru,1009,10,4.0,6.0
Segmentation fault(coredump)
----------------------------------------------
please help me in this
Thanks & regards
vijay



LinkBack URL
About LinkBacks


