Skip to main content

Command Palette

Search for a command to run...

Scansets

Updated
1 min readView as Markdown
Scansets
#include <stdio.h>
#define MAX 50

int main(){
    char str[MAX];
    printf("Enter the string:");
    scanf("%49[^\n]",str);
    printf("\nThe string is %s",str);
    }
#include <stdio.h>

int main() {
    char firstName[50], lastName[50];

    printf("Enter your full name (first name and last name separated by space or comma): ");

    // Using scanset to read input into two strings
    // Leading whitespace is skipped using the space before the scanset
    scanf(" %49[^, \n]%*[, ]%49[^\n]", firstName, lastName);

    printf("\nFirst Name: %s\nLast Name: %s\n", firstName, lastName);

    return 0;
}

Output:

#include <stdio.h>

int main() {
    char firstName[50], middleName[50], lastName[50];

    printf("Enter your full name (first name and last name separated by space or comma): ");

    // Using scanset to read input into two strings
    // Leading whitespace is skipped using the space before the scanset
    scanf(" %49[^, \n]%*[, ]%49[^, \n]%*[, ]%49[^\n]", firstName, middleName, lastName);

    printf("\nFirst Name: %s\nMiddle Name: %s\nLast Name: %s\n", firstName, middleName, lastName);

    return 0;
}

Output:

25 views

More from this blog

P

Programming Tutorials

89 posts