lundi 2 mars 2015

gets substring of a very long string after a comma and stores the each detail in a char array


#include <stdio.h>

#include <string.h>

int main( void ) {

const char *string[100000];

const char delims[] = ",";

const char *s = string;

char t[10][10400];

int j =0 ;

int words=0;

FILE *cfPtr;

if ((cfPtr = fopen( "pln.txt", "r" ) ) == NULL ) {

printf( "File could not be opened\n" );

} else {


fscanf(cfPtr,"%[^\n]",string);

pali =strlen(string);

do {

size_t field_len = strcspn(s, delims);

printf("\"%.*s\"\n", (int)field_len, s);


memcpy( t, &string[field_len], 7 );

t[7][j] = '\0';




s += field_len;

words ++;

j++;


printf("%s",t[0][j]);


} while (*s++);

printf("%d No of words \n", words);

fclose(cfPtr);

}





}

Aucun commentaire:

Enregistrer un commentaire