Answer the question
In order to leave comments, you need to log in
How to fix variable is being used without being initialized error?
When compiling, it constantly crashes Run-Time Check Failure #3 - The variable 'znak' is being used without being initialized.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j = 0, k, n = 0, r = 0, f = 0;
char num2[30];
char oper1[13];
char oper2[13];
char znak;
int result[30], chys1[20], chys2[20];
system("chcp 1251");
printf("Введіть операцію: \n");
gets_s(num2);
for (i = 0; num2[i] != '\0'; i++)
{
if (num2[i] == ' ')
{
oper1[i] = '\0';
znak = num2[i + 1];
i = i + 3;
for (i; num2[i] != ' ' && num2[i] != '\0'; i++)
{
oper2[j] = num2[i];
j++;
}
oper2[j] = '\0';
break;
}
else
{
oper1[i] = num2[i];
}
}
while (oper1[f] != '\0') {
f++;
}
for (k = 0; oper1[k] != '\0' && oper1[k] != '\0'; k++)
{
chys1[k] = oper1[k] - 48;
chys2[k] = oper2[k] - 48;
}
for (n; n < f; n++)
{
if (znak == '^')
result[n] = chys1[n] ^ chys2[n];
if (znak == '&')
result[n] = chys1[n] & chys2[n];
if (znak == '|')
(result[n] = chys1[n] | chys2[n]);
}
for (r; r < f; r++)
{
printf("%d", result[r]);
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
What is not clear in the phrase?
The variable 'znak' is being used without being initialized.
char znak = 0;
char znak;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question