Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 60 FILE *fp = fopen(argsInfo.inFileStr,"r");
- 61 /*pointer point to the malloc return value*/
- 62 char *ptr =NULL;
- 63 /*temp string hold the each line from the file*/
- 64 char temp[BUFSIZ];
- 65 /*if file doesn't exist*/
- 66 if(fp==NULL){
- 67 /*file doesn't exist error message*/
- 68 perror(argsInfo.inFileStr);
- 69 /*exit the programme*/
- 70 return TRUE;
- 71 }
- 72 /*read the file line by line*/
- 73 while(fgets(temp,BUFSIZ,fp)!=NULL){
- 74 /*save pointer for strtok_r*/
- 75 char *saveptr;
- 76 /*token hold each tokenlized string*/
- 77 char *token;
- 78 /*for loop to tokenlize the string*/
- 79 for(token = strtok_r(temp,STR_FILE_TOK_SEPARATOR,&saveptr);
- 80 token!=NULL;
- 81 token=strtok_r(NULL,STR_FILE_TOK_SEPARATOR,&saveptr)){
- 82 *(dynamicString+index) =
- 83 (char*)realloc(*(dynamicString+index),sizeof(char*)*(index+1)); /*dynamic allocate memory for each token*/
- 84 ptr = (char*)malloc((strlen(token)+1)*sizeof(char));
- 85 /*copy the token the the memory*/
- 86 strcpy(ptr,token);
- 87 /*assign the pointer the the pointer array*/
- 88 *(dynamicString+index)=ptr;
- 89 /*increment the index*/
- 90 index++;
- 91 }
- 92 }
- 93 }
- 94 /*case read from command line*/
- 95 else{
- 96 /*read from optind un argc*/
- 97 while(counter<argc){
- 98 *(dynamicString+index)=NULL;
- 99 /*realloc the memory for each user input token*/
- 100 dynamicString =
- 101 (char**)realloc(dynamicString,
- 102 sizeof(char**)*(index+1));
- 103 /*copy each user input string to the memory space*/
- 104 // strcpy(*(dynamicString+index),argv[counter]);
- 105 *(dynamicString+index) = argv[counter];
- 106 /*increment the counter*/
- 107 counter++;
- 108 /*increment the index*/
- 109 index++;
- 110 }
- 111 }
- 112 /*loop through all the string in the dynamic allocated memory*/
- 113 for(counter = 0; counter < index;counter++){
- 114 /*if string contain float point*/
- 115 if(strchr(dynamicString[counter],'.')==NULL){
- 103,1 71%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement