Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <limits.h>
- #include <string.h>
- int maxLines;
- int main(int argc, char *argv[]) {
- if(argc != 3){
- printf("Improper execution...\n");
- }
- // Good command sent.
- else{
- // fileReader(argv[1]);
- char delims[] = {"\n"};
- char *result = NULL;
- int i = 0, j;
- char sent[1000];
- char *gameArray[1024];//32 word
- strcpy(sent, argv[1]);//strtok destory string, argv[n] is read only.
- char *buffer = NULL;
- int string_size,read_size;
- FILE *handler = fopen(argv[1],"r");
- // Handles the reading of the file and printing for the first time.
- // This also saves each NEWLINE (i.e) each game to the parray
- if (handler)
- {
- //find the last byte of file
- fseek(handler,0,SEEK_END);
- //create string size
- string_size = (int)ftell(handler);
- //go back to the start of the file
- rewind(handler);
- //allocate a string that can hold it all
- buffer = (char*) malloc (sizeof(char) * (string_size + 1) );
- //Read entire file
- read_size = fread(buffer,sizeof(char),string_size,handler);
- //End the buffer with NULL character.
- //This buffer now contains a very long string with all the contents of the
- //passed games file.
- buffer[string_size] = '\0';
- //We will tokenize the long buffer string here with the NEWLINE '\n' as a delimiter
- result = strtok(buffer, delims);
- //Save new line i.e new game to next index of the array.
- gameArray[i++] = result;
- while(NULL!= (result=strtok(NULL, delims))){
- gameArray[i++] = result;
- }
- // Initial Print of File List Happens here
- for(j=0; j < i;++j)
- printf("%s\n", gameArray[j]);
- maxLines = j;
- }// End IF
- }// End Else
- // AT THIS POINT YOU HAVE AN ARRAY OF GAMES WITH EACH LINE REPRESENTING A GAME
- // WHAT YOU NEED TO DO IS TOKENIZE ON ',' AND SAVE THAT TO AN ARRAY OF NAME, PRICES AND AN
- // ARRAY OF QUANITY
- // SO THAT YOU CAN THEN REQUEST INPUT FROM THE USER. IE IF THEY SAY 2, THEN YOU WOULD GO TO
- // PRICES[2] = PRICES[2]-1 or something like that ....
- // ****** TRYING TO GET THIS WORKING ****** //
- int n;
- while(1){
- scanf ("%d",&n);
- char exit = (char)n;
- if(exit == 'q'){
- printf("Bye...");
- break;
- }
- else if(n < 0 || n > maxLines){
- printf("ERROR Not Line Matches...");
- break;
- }
- else{
- printf("Lets Handel the commands here");
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement