All Questions
Tagged with if-statement c
2,224 questions
0
votes
4
answers
168
views
Can I check the value of the array within a two dimensional array in C
char array[8][13];
memset (&array, 0, sizeof(array));
/* this is a rough example this is in a struct that is memset */
if (array[0])
{
printf("this is valid"); /* again this code is ...
1
vote
3
answers
114
views
Switch inside while and break statement
Suppose I have a piece of C code
while(1)
{
switch(a){
case 1:
if(b==1)
break;//first break
break;//second break
}
}
...
0
votes
1
answer
93
views
Why is this code still adding 1 to i even when the if statment that does so isnt called in C? [closed]
So this is my code:
#include <stdio.h>
#define SIZE 10
int main(void)
{
int x,p[SIZE],i=0;
printf("type some characters\n");
while((x = getchar()) != EOF && i<...
1
vote
2
answers
99
views
How to debug this substring matching code?
I am a beginner in C programming, and this is a string matching code I wrote. It aims to find the positions where the substring t appears in the string s and print them. The use of pointers is ...
2
votes
1
answer
110
views
Why does if (fork() || fork() || fork()) behave differently?
Why does the second piece of code does not create 7 processes just like the first code?
Anywhere it says that fork()'s child process runs exactly from the same point as the parent. Shouldn't this mean ...
0
votes
1
answer
94
views
How to prevent blank lines and remove extra spaces in C word-per-line output?
I'm reading K&R's The C Programming Language and currently working on Exercise 1-12. The issue I'm facing isn't with completing the exercise itself, but with fixing a bug that has come up as a ...
0
votes
2
answers
85
views
i*=j ==x and i=i*j ==x behaving differently in C
I have these two code snippets that are acting differently:
int i=2,j=3;
if (j*=i == 2){
printf("yes, i= %d, j= %d",i,j);
} else {
printf("no, i= %d, j= %d",i,j);
}
int i=...
1
vote
2
answers
84
views
gcc Preprocesor failed on #if
I have strange problem as gcc preprocesor failed on #if directive.
Sample code:
#include "stdio.h"
enum BoardTypes{
Board_IO_WithAdc,
Board_IO_WithEnc,
Board_PakelcIn,
...
2
votes
2
answers
172
views
In what conditions is one comparison for "if" and "if-else" at С as at assembly?
For x86 assembly the "cmp" instruction sets two flags: "ZF" and "CF", allowing to determine if two integers are equal or greater or less with a single comparison. How ...
1
vote
1
answer
92
views
Why it has to have a default return value when implementing binary insertion using recursion?
The searchInsert function return the index where the target should be based on the value. Why it should have the line
return -1;
in the following code? I thought I included all the possible outcomes ...
-1
votes
2
answers
96
views
How can i make a C program exit when key Q is pressed?
i am making a counting program, and i want to add a feature that quits the program, but i don't really know how to do it. i have seen examples on how to do it, but all of them are for windows. please ...
0
votes
2
answers
77
views
Code output repeats the else section of this if else section
Soo, whenever I run this code, it only repeats the last section on the if else block. It only outputs that one printf repeatedly.
I did use the sscanf thing to check if I can and to prevent buffer ...
1
vote
2
answers
80
views
cs50 scabble problem not working. can anyone help plz?
I'm doing the cs50 scrabble problems from problem set 2 and my 'point' function doesn't add points correctly. The function keeps ignoring all the 'if' and 'else if' statements even when there are char ...
0
votes
1
answer
75
views
An 'if' statement isn't executing when a mask is applied to a variable even though it should
In my example, I’m creating an integer variable called testVar and I make it equal to A1 in hexadecimal. When printing out the variable, it shows that it should indeed be equal to A1 in hexadecimal. ...
0
votes
1
answer
94
views
Defining a variable inside an if condition and program doesn't enter
In functions in C, I understand that the stack is normally used to store paramaters passed to a function, and for the local variables for the function. I know that this is compiler and platform-...