• Scanning a single character in c 2019-03-22

    This question already has an answer here: Scanf skips every other while loop in C 10 answers I have used the following code snippet to read several values but the single character constant variable rating is not accepting any value. It doesn't execut

    Tags: scanf, char
  • Add and print multiple char in C 2018-04-13

    I'm creating a Dice Game, where the user rolls 3 dice and gets some random outputs (up to integer 6). My next step is to add those 3 values obtained and get its sum. How do I achieve this? Any suggestion would be helpful. Here's my source code: //Rol

    Tags: int, scanf, char, add
  • Specifing the maximum string length to scanf dynamically in C (like "%*s" in printf) 2015-02-11

    I can specify the maximum amount of characters for scanf to read to a buffer using this technique: char buffer[64]; /* Read one line of text to buffer. */ scanf("%63[^\n]", buffer); But what if we do not know the buffer length when we write the code?

    Tags: size, buffer, scanf
  • Fgets skipping inputs 2014-10-11

    This question already has an answer here: fgets doesn't work after scanf 4 answers I've tried looking around and I can't seem to find where the error lies. I know it must have something to do with the way I used fgets but I can't figure out for the l

    Tags: scanf, fgets
  • Few novice questions about C, problems with scanf and conversion specifiers 2014-09-18

    Here you can see my source code: #include <stdio.h> int main() { char yourname; char yoursex; int yourage = 0; printf("Hey, what's your name?\n"); printf("My name is: "); scanf("%s", &yourname); printf("Oh, hello %s! \n\n", &yourname);

    Tags: printf, scanf
  • Checking input to see if user has entered control-d 2014-08-27

    Pretty new to C, and I have what may be a pretty simple question. I am writing a program in C which reads a series of strings from the user. The program is supposed to do something with these strings after the user indicates that he is done entering

    Tags: string, user input, scanf
  • Program stops after assigning values to struct using scanf 2014-06-20

    In the following code, the program stops without any errors when I assign it's members values using scanf. #include <stdio.h> typedef struct { int hours, minutes, seconds; } Time; int main (void) { Time getTime (void); Time time; time = getTime

    Tags: struct, scanf
  • How can I read input while it exists? 2014-05-17

    #define _CRT_SECURE_NO_WARNINGS #include <cmath> #include <cstdio> #include <string> int main(){ char s = ' '; while (s != NULL) { scanf ("%c", &s); int a = 0; if (s == '"') { if (a == 0) printf("``"); else printf("''"); a = 1-

    Tags: scanf, eof
  • What's wrong with my program (scanf, C++)? 2014-05-17

    What wrong with this program? #define _CRT_SECURE_NO_WARNINGS #include <cstdio> using namespace std; int N; char x[110]; int main() { scanf("%d", &N); while (N--) { scanf("0.%[0-9]...", &x); printf("the digits are 0.%s\n", x); } return

    Tags: scanf
  • How can I use scanf to get input from the next line of input data? 2014-05-09

    I have 5 lines of input and I only care about using two of them (they're in a text file): 1 -- input function one L 123.0 21.0 2 -- input function 2 2.0 3.0 3.0 2.0 I want to use 1 from the first line, and then I want to skip to line 2. After I've us

    Tags: string, scanf, char
  • Trouble with using getchar() instead of scanf() 2014-05-07

    I'm having trouble making this exercise for C-programming. I need to use the getchar()-method instead of the scanf(). When I use the scanf, everything works perfect when I type for instance 7. However when I use the getchar() and type 7, I will get t

    Tags: scanf, getchar
  • Having Trouble using scanf with char arrays 2014-03-12

    I'm a student learning C, (my previous experience is all python) and am having trouble debugging a program. The following section in particular has me confused -- I believe I am using scanf or printf incorrectly (and I must use these two, no other fu

    Tags: arrays, scanf
  • How to get errors to print if chars are entered using scanf in C 2013-09-17

    I'm experimenting with c at the moment and this program is suppose to get the user to input a number between ranges 10-100 if he enters anything that doesn't meet these conditions, the program will exit with an error code 1. anything that meets condi

    Tags: scanf, char, exit code
  • ruby how read user input in scanf-style like in C++ 2013-02-09

    I am new in Ruby. I need to read from user input (n) numbers and in C++ i used this code for(i=0;i<N;i++) { scanf("%d",&array[i]); } this code read exactly (n) numbers separated by any white spaces (tabs, spaces, newlines). How i can do this i

    Tags: ruby, scanf
  • How to read numbers separated by space using scanf 2012-05-03

    I want to read numbers(integer type) separated by spaces using scanf() function. I have read the following C, reading multiple numbers from single input line (scanf?) how to read scanf with spaces It doesn't help me much. How can I read numbers with

    Tags: scanf
  • Rounding Error in Integer Assignment 2012-04-26

    How do you explain the Rounding happening here?I thought assigning float values to Int's always cause loss of value after decimal? int z=39.99999999999999999999999; printf("%d",z); // gives 40 Thanks --------------Solutions------------- You can't hav

    Tags: floating point, printf, rounding, scanf
  • What's the behavior of scanf when the format string ends with a newline? 2012-04-22

    For the following code: (assuming x has been defined) scanf("%d\n", &x); printf("foo"); I expect the program to print foo if I press 1 and ENTER, but this is not the case. I have to press 1, ENTER, 2, ENTER to see it print foo. Now the question i

    Tags: scanf
  • Understanding that scanf is doing in this code 2012-04-20

    Please help me in understanding the below code. The function get_digit takes a character argument by address. I am unable to get what scanf("%1[0123456789]", ch) does here. If I give 1234 on the terminal then it takes only the first digit. Same is if

    Tags: scanf
  • keep doing scanf for all input in command line. C program 2012-04-17

    I am trying to get all the input from the command line and putting it in a linked list. the numbers from the command line are of this format 0-1 2-3 4-9 etcc Here is what I did to store a pair of numbers in two variables: scanf("%d-%d", &a, &

    Tags: command line, input, scanf
  • Getting around null char from scanf 2012-04-13

    I have got my strtok working, but now because I am using scanf which ends the string with NULL char my program is only grabbing one line from redirected standard in. eg. scanf("%s" , input); token = strtok (input, ", \n"); while(token != NULL){ i +=

    Tags: scanf, strtok

Copyright (C), All Rights Reserved.

processed in 4.337 (s). 9 q(s)