Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am writing a C program that reads in decimal and hexidecimal values and displays the ascii value. I am having trouble differientiating between the

I am writing a C program that reads in decimal and hexidecimal values and displays the ascii value. I am having trouble differientiating between the two inputs. I am using isdigit and isxdigit but my input for the hexidecimal input is in the format 0x... to show that it is a hex input. How can I adjust my code to accept these values as hex and differentiate between hex and dec? I have included my code.

#include #include #include #include #include int main() { char line[1024]; for(int i=0;i<1024;i++){

line[i]='\0'; }

int len; int val; char *p; while((p = fgets(line, sizeof(line), stdin)) != NULL) { /* read a line from standard input */ len = strlen(line)-2; for(int i = 0; i < len; i++) { p = &line[i]; if(isxdigit(line[i])) { sscanf(p, "%x", &val); printf("%c", val); } else if(isdigit(line[i])){ sscanf(p, "%d", &val); printf("%c", val);

} /*else if(isalpha(line[i])) { printf("Error "); }*/ } } printf(" "); return 0;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions

Question

Understand what a service-oriented culture is.

Answered: 1 week ago

Question

Explain the key areas in which service employees need training.

Answered: 1 week ago