C language doesn't scan variable

C language doesn’t scan variable after reading that variable as string(or char) instead of integer But the most weird is that it is entering in infinite loop int main( ){ int answer; printf("Hello\n"); while (answer != 3){ start();//It is declared above scanf("%d",&answer); switch (answer) { case 1:{ showCenters();//Also declared break;} case 3:{ break;} default:{ printf("Invalid… Read More C language doesn't scan variable

How to write a program to ask the user for an input between 1-20 but it prints "invalid input" if user enters any char or string or (-ve) integers?

I am working on a simple project of C-Programming called "Election System". But i want to optimize it so the output will never be wrong. So for this i need this:- How to write a program to ask the user for an input between 1-20 but it prints "invalid input" if user enters "any character… Read More How to write a program to ask the user for an input between 1-20 but it prints "invalid input" if user enters any char or string or (-ve) integers?

why is the c function not scanning 2nd time using scanf function?

I am stuck in this program, help me, it’ll be appreciatable. But, scanning the characters together might work. I want to know why is scanf not asking for the character in 2nd time. #include <stdio.h> int main() { printf("–Mathematical operations on character to get other character–\n"); char a, b; printf("Enter the 1st character: \n"); scanf("%c",… Read More why is the c function not scanning 2nd time using scanf function?

segmentation fault error when reading a file in C

I was trying to read a file char by char but the debugger when reaches the fscanf gives back a segmentation fault error, here’s my code: int main(){ FILE *inFile; char *carattere = NULL; inFile = fopen("../file.txt", "r"); if (inFile == NULL){ return -1; } while(fscanf(inFile, "%c", carattere) != EOF){ //segmentation fault printf("%c ", *carattere);… Read More segmentation fault error when reading a file in C