let's say I want to take an input from a file like this :-
"8313515769001870,GRKLK,03/2023,eatcp,btlzg" "6144115684794523,ZEATL,10/2033,arnne,drrfd" for a structure I made as follows
typedef struct{ char Card_Number[20]; char Bank_Code[6]; char Expiry_Date[8]; char First_Name[30]; char Last_Name[30]; }Card; This is my attempt to read the input from a file named 'file' in the reading mode, the str in fgets is storing the right string but it isn't getting absorbed c[i]:
FILE * fptr; int count=0; fptr= fopen("file","r"); Card *c = (Card*)calloc(10,sizeof(Card)); printf("StartAlloc\n"); int i=0; char str[1000]; fgets(str,80,fptr); if(fptr==NULL) {return 0;} do{ sscanf(str,"\"%[^,],%[^,],%[^,],%[^,],%[^,]\" \n",c[i].Card_Number,c[i].Bank_Code,c[i].Expiry_Date,c[i].First_Name,c[i].Last_Name); i++; }while(fgets(str,80,fptr)!=NULL); I do not understand why the regex %[^,] is not capturing the individual elements, I have wasted a lot of time, and help would be greatly appreciated.
scanfformat strings are not regexes.strtokinstead