Im new to C and i really need your help
Detail: https://www.codingame.com/training/easy/logic-gates
All of that works okey (for me), except printf("%c ",output_name[0][i]);
My idea is print the name first then “-” and “_” but my code only work with one-character name, i tried several ways but still not work.
Here is my code
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main()
{
int n;
scanf("%d", &n);
int m;
scanf("%d", &m);
char input_name[n][9];
char input_signal[n][26];
char output_name[m][1];
char type[m][5];
char input_name_1[m][1];
char input_name_2[m][1];
int input_value_store_1;
int input_value_store_2;
for (int i = 0; i < n; i++) {
scanf("%s%s", input_name[i], input_signal[i]);
}
for (int i = 0; i < m; i++) {
scanf("%s%s%s%s", output_name[i], type[i], input_name_1[i], input_name_2[i]);
}
for (int i=0; i < m; i++) {
printf("%c ",output_name[0][i]);
for (int j=0; j<sizeof(input_signal[i]); j++)
{
if (input_signal[0][j] == '-' ) input_value_store_1 = 1;
else input_value_store_1 = 0;
if (input_signal[1][j] == '-' ) input_value_store_2 = 1;
else input_value_store_2 = 0;
if (strcmp(type[i], "AND") == 0) {
if ((input_value_store_1 == 1) && (input_value_store_2 == 1))
printf("-");
else printf("_");
}
else if (strcmp(type[i], "OR") == 0) {
if ((input_value_store_1 == 1) || (input_value_store_2 == 1))
printf("-");
else printf("_");
}
else if (strcmp(type[i], "XOR") == 0) {
if (((input_value_store_1 == 1) || (input_value_store_2 == 1)) && (input_value_store_1 != input_value_store_2))
printf("-");
else printf("_");
}
else if (strcmp(type[i], "NAND") == 0) {
if (!((input_value_store_1 == 1) && (input_value_store_2 == 1)))
printf("-");
else printf("_");
}
else if (strcmp(type[i], "NOR") == 0) {
if (!((input_value_store_1 == 1) || (input_value_store_2 == 1)))
printf("-");
else printf("_");
}
else if (strcmp(type[i], "NXOR") == 0) {
if (!(((input_value_store_1 == 1) || (input_value_store_2 == 1)) && (input_value_store_1 != input_value_store_2)))
printf("-");
else printf("_");
}
}
printf("n");
}
return 0;
}
New contributor
Blu e’s is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.