I'm writing a C program that reads table data from a .txt file, applies changes to it and prints the modified table to a different .txt file. Part of the program is the function that prints and empty line before the line entered in the terminal after the irow argument. Here's how the program is compiled and run:
gcc -Wall -Wextra -Werror -o main main.c
./main irow [row] <tab1.txt >tab2.txt
Part of the program that handles the input:
int insertRow(char*argv[], int row_number) {
row_number = 0;
for(int i = 0; argv[i]; i++) {
if ( isdigit(argv[i][0]) && (strcmp(argv[i - 1], "irow") == 0))
if((argv[i][0] - '0') > 0)
row_number = argv[i][0] - '0';
}
return row_number;
}
Then the row_number is used in the main method to perform the changes on the table.
The code works and performs what it's supposed to, however I haven't yet come up with a better way of reading the [row] parameter from the argument vector. How can I read not only the first digit but the whole integer inside the string of that argument?