I need to achieve the following:
The user will enter the following command by keyboard: cousins entry.txt -t -n 5
Where cousins is the exercise, input.txt a file that contains numbers, -t to indicate that threads will be created, and < strong> -n to indicate how many threads. Storing each of these data in an independent variable is what I need, and I've written the following code, but I can not make it work.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char cadena [100];
printf ("\nLa instrucción, debe tener el siguiente formato:\n");
printf("primos entrada.txt [-t | -p] [-n N] -> ");
/* primos entrada.txt -t -n N */
fgets (cadena, 100, stdin);
//
int longitud = strlen(cadena) - 1;
char primos[6];
char entradaTXT[10];
char tipo[2];
char cantidad[2];
char n[2];
// Ejercicio Primos
fflush(stdin);
for(int i = 0; i < 6; i++) {
primos[i] = cadena[i];
}
// entrada.txt
fflush(stdin);
int j = 0;
for(int i = 8; i < 18; i++) {
entradaTXT[j] = cadena[i];
j++;
}
// Tipo (Hilos o procesos)
fflush(stdin);
j = 0;
for(int i = 20; i < 21; i++) {
tipo[j] = cadena[i];
j++;
}
// Cantidad de hilos o procesos
fflush(stdin);
j = 0;
for(int i = 23; i < 24; i++) {
cantidad[j] = cadena[i];
j++;
}
//printf("\n%s",&primos[6]);
printf("\n%s\n%s\n%s\n",&primos[6],&entradaTXT[10],&tipo[10]);
fflush(stdin);
return 0;
}
The result I get when compiling and executing is the following:
Apparently all the variables are being stored in a single chain, but I do not understand why, could someone give me a hand?