Question

In: Computer Science

C PROGRAMMIMG I want to check if my 2 input is a number or not all...

C PROGRAMMIMG

I want to check if my 2 input is a number or not

all of the input are first stored in an array if this the right way?

read = sscanf(file, %s%s%s, name, num, last_name);

if(strcmp(num, "0") != 0)

printf("Invalid. Please enter a number.")

Solutions

Expert Solution

CODE:

#include <stdio.h>

#include <string.h>

int main(void) {

  char name[10];

  char num[10];

  char last_name[10];

  int i;

scanf("%s%s%s", name, num, last_name);

// to check if all the digits in the array are numbers

int numberOfDigits=0;

for(i=0;i<strlen(num);i++){

  // if the number is between 0 and 9

  if(num[i] >= '0' && num[i] <= '9')

    numberOfDigits++;

}

if(numberOfDigits==strlen(num))

  printf("Number\n");

else

  printf("Invalid. Please enter a number.\n");


return 0;

}

OUTPUT:

Please upvote if you like my answer and comment below if you have any queries or need any further explanation.


Related Solutions

C++ If I want to ask the user to input the variables in a vector, how...
C++ If I want to ask the user to input the variables in a vector, how can I do that? I'm trying to implement this in a program with matrices. So the user should enter how many rows and columns they want, then enter the values Can you help me out
Need to check if File is successfully opened? C++ It works when I input the right...
Need to check if File is successfully opened? C++ It works when I input the right txt file. But, it keeps stating, File successfully open." even I put in a non-existing file. Here are the specifications: Develop a functional flowchart and then write a C++ program to solve the following problem. Create a text file named first.txt and write your first name in the file. You will be reading the name of the file from the keyboard as a string,...
C PROGRAMMING LANGUAGE PROBLEM TITLE : ARRAY usually, if people want to input number into an...
C PROGRAMMING LANGUAGE PROBLEM TITLE : ARRAY usually, if people want to input number into an array, they will put it from index 0 until N - 1 using for. But, Bibi is bored to code like that. So, she didin't want to input the number that way. So Bibi challenged you to make a program that will read a sequence (represent index) that she made, then input the number to an array but input it with the same sequence...
Can I get a detailed answer going threw all the steps so I can check my...
Can I get a detailed answer going threw all the steps so I can check my answer. A total debt of $ 1,000 due now, $4000 due 2 years from now, and $6000 due 5 years from now is to be repaid by 3 payments. (1) The first payment is made now. (2) The second payment, which is 80% of the first, is made at the end of 30 months from now. (3) The third payment, which is 60% of...
this is my code I want the opposite i want to convert a postfix expression to...
this is my code I want the opposite i want to convert a postfix expression to infix expression #include <iostream> #include <string> #define SIZE 50 using namespace std; // structure to represent a stack struct Stack {   char s[SIZE];   int top; }; void push(Stack *st, char c) {   st->top++;   st->s[st->top] = c; } char pop(Stack *st) {   char c = st->s[st->top];   st->top--;   //(A+B)*(C+D)   return c; } /* function to check whether a character is an operator or not. this function...
I want my answer typed.                                      I. What i
I want my answer typed.                                      I. What is presbyopia? Hyperopia? Myopia? 2. Which cranial nerves assesses eye function and acoustic function? 3. What is the Rinne test? Weber test? 4. Do you or anyone you know have any of the issues/symptoms/conditions mentioned in the video? Is it due to genetics or aging? How is it being managed?
Hello! I have worked out all these questions, but want to double check them with your...
Hello! I have worked out all these questions, but want to double check them with your answers before submitting them. Thanks! 1. On December 31, 20X1, a company adopted the dollar-value LIFO inventory method. Inventory at the end of 20X1 for its only inventory pool was $400,000 under the dollar-value LIFO method. At the end of 20X2, inventory at year-end cost is $473,000 and the cost index is 1.10. At the end of 20X3, inventory at year-end cost is $492,000...
Python I want to name my hero and my alien in my code how do I...
Python I want to name my hero and my alien in my code how do I do that: Keep in mind I don't want to change my code except to give the hero and alien a name import random class Hero:     def __init__(self,ammo,health):         self.ammo=ammo         self.health=health     def blast(self):         print("The Hero blasts an Alien!")         if self.ammo>0:             self.ammo-=1             return True         else:             print("Oh no! Hero is out of ammo.")             return False     def...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input system for a university student, where they put the season and year of when they started their uni course. For example the system will ask "What year did you start your degree?", the user will input "Autumn/2022" as a string. Now from a string format as shown, it should take that user input and calculate for example +2 or +3 years to the date....
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input system for a university student, where they put the season and year of when they started their uni course. For example the system will ask "What year did you start your degree?", the user will input "Autumn/2022" as a string. Now from a string format as shown, it should take that user input and calculate for example +2 or +3 years to the date....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT