Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define EXIT 4
- #define SIZE_STR 20
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string.h>
- void copyTextFile(FILE* dst, FILE* src);
- int printMenu(void);
- int searchFile(char str[], char** data_file, int colsize, int rowsize);
- int main()
- {
- FILE* csvfile;
- int c,choice=0, countRow=0, countcol=0,flag=0,row,col;
- char str[SIZE_STR] = {0};
- char** data;
- char* ptr;
- csvfile = fopen("example.csv", "r");
- c = fgetc(csvfile);
- while (c != EOF)
- {
- //printf("%c",(char)c);
- c = fgetc(csvfile);
- if (c == ',')
- {
- countcol++;
- }
- else if (c == '\n')
- {
- countRow++;
- }
- else
- {
- ptr = (char*)malloc(sizeof(char));
- ptr = c;
- data[countRow][countcol] = ptr;
- }
- }
- for (row = 0; row < countRow; row++)
- {
- for (col = 0; col < countcol; col++)
- {
- printf("%c", data[row][col]);
- }
- }
- countcol = countcol / countRow;
- printf("\n %d-cols", countcol);
- printf("\n %d-rows", countRow);
- while (choice!=EXIT)
- {
- choice = printMenu();
- switch (choice)
- {
- case 1:
- {
- flag=searchFile(str, data,countcol,countRow);
- if (flag !=0)
- {
- printf("Value was found in row %d", flag);
- }
- else
- {
- printf("Value Wasn't Found");
- }
- break;
- }
- case 2:
- {
- printf("");
- break;
- }
- case 3:
- {
- printf("");
- break;
- }
- default:
- {
- printf("Try agian.");
- break;
- }
- }
- }
- fclose(csvfile);
- getchar();
- }
- int printMenu(void)
- {
- int choice = 0;
- printf("Please enter your choice:\n1 - Search a term in the document.\n2 - change a value in a specific place.\n3 - copy a value from one place to another");
- scanf("%d",&choice);
- return choice;
- }
- int searchFile(char str[], char** data_file,int colsize,int rowsize)
- {
- int col=0, row=0;
- int indexRowOrFlag=0;
- printf("Enter value to search: ");
- fgets(str, SIZE_STR, stdin);
- str[strlen(str) - 1] = "\0";
- for (row = 0; row < rowsize; row++)
- {
- for (col = 0; col < colsize; col++)
- {
- if (strcmp(str, data_file[row][col]) == 0)
- {
- return row;
- }
- }
- }
- return indexRowOrFlag;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement