logo
down
shadow

Scanf in visual studio not accepting multiple cases of characters


Scanf in visual studio not accepting multiple cases of characters

By : Zaenon
Date : October 23 2020, 06:10 PM
fixed the issue. Will look into that further I'm creating a conversion project for letters/numbers ASCII table. My code is supposed to be 'interactive', so the user would type 'y' or 'n' to answer questions on the screen. However, it doesn't want to do this twice... , I'm not sure what confuses you.
Use
code :
char foo;
scanf(" %c", &foo);
int bar;
scanf("%d", &bar);
int height;
int width;
scanf("%d %d", &height, &width);
int height;
int width;
if (scanf("%d %d", &height, &width) != 2) {
    // handle the error, maybe exit the program.
}
#define _CRT_SECURE_NO_WARNINGS  // you said Visual Studio? Without it you should get
                                 // warnings about some functions being insecure.

#include <ctype.h>   // isalpha()  returns true if the value is a letter
#include <stdlib.h>  // EXIT_SUCCESS
#include <stdio.h>   // puts(), printf(), scanf()

int main(void)
{
    for(;;) {  // for-ever ... endless loop since the user exits by answering
               // 'n' or 'N' two times

        puts("Would you like to convert a number today?\nPlease press Y or N:");
        char input;
        if (scanf(" %c", &input) != 1)  // We reached EOF ... end of file
            break;                      // that's improbable for stdin,
                                        // but input could be redirected to
                                        // read from a file instead.

        if (input == 'y' || input == 'Y') {
            puts("\nThank you!\nWhat number?");
            int number;
            scanf("%d", &number);

            if (isalpha((char unsigned)number))  // *)
                printf("\nYour Number \t ASCII letter\n%d\t %c\n\n", number, number);
            else
                puts("Sorry, but that's not the ASCII code of a letter :(\n");
        }
        else if (input == 'n' || input == 'N') {
            puts("\nWould you like to convert a letter instead?\nPlease press Y or N:");
            scanf(" %c", &input);

            if (input == 'y' || input == 'Y') {
                puts("\nGreat choice adventurer!\nWhat letter will it be today?");
                char letter;
                scanf(" %c", &letter);

                if (isalpha(letter))
                    printf("\nYour letter \t ASCII code\n%d\t %c\n\n", letter, letter);
                else
                    puts("Sorry, but that's not a letter :(\n");
            }
            else if (input == 'n' || input == 'N') {
                puts("\nDifficult to please, I see...\n\nI suggest you move on with that attitude!\n");
                puts("Bye bye then.");
                return EXIT_SUCCESS;
            }
        }
        else {
            puts("Sorry I did not recognize your command... Please retry.");
            puts("Press Y or N next time!\n");
        }
    }
}


Share : facebook icon twitter icon
unit test cases visual studio

unit test cases visual studio


By : user3488487
Date : March 29 2020, 07:55 AM
To fix this issue If the reset of the organization you're in is using MSTest, that's a good reason to use it. If you are doing this on your own, that reasoning is irrelevant.
For third-party frameworks, nUnit works well with VS2010, and it's easy to find information on how to use it. It's the only one I've used, since my previous employer didn't pony up for the MS Test licensing.
Visual Studio unit testing - multiple cases like Nunit

Visual Studio unit testing - multiple cases like Nunit


By : Hans Kevin Ttito San
Date : March 29 2020, 07:55 AM
it helps some times It is not possible out of the box. But for VS 2010 atleast you can write MSTEST Extensions to provide nearly the same feature. Check this blog. But it is not nearly as good as NUnit's TestCase.
scanf on Visual Studio 2015

scanf on Visual Studio 2015


By : Anand
Date : March 29 2020, 07:55 AM
hop of those help? The problem is that the "%[^\n]" format specifier will leave the newline in the input buffer. The following scanf won't skip that newline because the %[] format specifier doesn't skip leading whitespace by default. (By contrast, most of the format specifiers like %s, %d and %f do skip whitespace by default.)
To solve the problem, you can put a space at the beginning of the format string, like so
code :
scanf(" %[^\n]", password);
       ^ this space forces scanf to skip any leading whitespace, including newlines
Accepting user input in Visual studio Code

Accepting user input in Visual studio Code


By : More than A Feely
Date : March 29 2020, 07:55 AM
like below fixes the issue The "Debug Console" in VS Code is written to by debug adapters, and the text box at the bottom is used for expression evaluation (what you type here goes to a debug adapters evaluateRequest method).
The "Unable to find thread for Evaluation" messge is because "global evaluation" is not supported - the Python extension will only evaluate expressions when there is an active thread. If you hit a breakpoint and then type 1+1 in this box, you'll see it print 2:
scanf skipping lines in visual studio 2015

scanf skipping lines in visual studio 2015


By : Tom G.
Date : March 29 2020, 07:55 AM
hope this fix your issue I'm unsure if the scan_f is causing my program to skip lines while it's being debugged. The first printf(""); runs and accepts and input, however the second one outputs but doesn't accept and input and jumps to the third printf(""); . I initial was using a getchar but as I'm unfamiliar with C I reverted back to scanf_s until I'm more familiar with it.
Related Posts Related Posts :
  • Random function stuck on one number
  • printf following zeros to a certain degree
  • Measuring CPU clocks consumed by a process
  • How is a CRC32 checksum calculated?
  • Tips on redefining a register bitfield in C
  • Converting a program from c to bash script
  • Static library not included in resulting LLVM executable
  • What is the meaning of "wild pointer" in C?
  • Reading DWORD from binary file
  • Efficient way to find divisibility
  • Whats the fastest, portable way to hash pointers we know are pointer aligned to a fixed size int?
  • Why does my summation program behaves weird?
  • How to determine values saved on the stack?
  • Thread scheduling C
  • C - converting to 2s complement
  • wireless networks c program
  • From where does the uboot get the information about flash, RTC, RAM in uboot/kernel development
  • printf behaviour in C
  • Measure size and way-order of L1 and L2 caches
  • Efficient copy of entire directory
  • Efficient way to create/unpack large bitfields in C?
  • getnameinfo prototype asks for sockaddr not sockaddr_in?
  • Linked List Sorting with Strings In C
  • Typecasting a floating value or using the math.h floor* functions?
  • Problem implementing sorting algorithm in C with an array of structs
  • How to copy a ram_base file to disk efficiently
  • How to fix casting a pointer to an integer?
  • How to round floating point numbers to the nearest integer in C?
  • PIC C - Sending 200 values over USB, but it only sends 25 or so of them
  • How do you return a string from a function correctly in Dynamic C?
  • Monotonic clock on IRIX
  • setsockopt (sys/socket.h)
  • How to make C program wait (on Linux)?
  • i find a problem using atoi() method in ansi c?
  • Why is this array being initialized in an odd way?
  • How to execute commands in chroot?
  • Microsecond (or one ms) time resolution on an embedded device (Linux Kernel)
  • Question about variable definitions in functions
  • SMTP on C: STARTTLS via OpenSSL
  • fetch value of ipaddress
  • Binary expressions in C
  • Why do char * and char ** have the same value?
  • problem in allocating kernel memory by malloc() from user space?
  • dangling pointer, reason for value change after free()?
  • How to compile C program with multiple files in Xcode
  • Can you make an incrementing compiler constant?
  • Reading data from text file in C
  • SQLite's test code to production code ratio
  • Displaying an inverted pyramid of asterisks
  • sd spi mode in C language
  • printf("%2d") in C programming
  • Add a certain number of bytes to a void pointer in C
  • How should I protect against hard link attacks?
  • What's the difference between unsigned long/long/int in c/c++?
  • Get an input from keyboard without 'return' in C
  • How to convert if to switch-case in c
  • C: swapping two pointer value
  • What does \x mean in c/c++?
  • run a command line argument prog
  • Pass a dynamic structure by reference? [C]
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk