C program help
4. Write a function called scan_hex. Here is its prototype:
void scan_hex(int *xptr);
Here is an example of its use, in conjunction with print_decimal. Assume that the user will type a non-negative hex number as input. Also, assume that the “digits” a-f are in lower case. Let’s say the user types 1b
int x;
scan_hex(&x);
print_decimal(x);
MODIFY THIS CODE
// function inputs a non-negative integer and stores it into *xptr.
// The format of the input is a base 16.
void scan_hex(int *xptr) {
char buffer[256];
char newline;
*xptr = 0;
scanf("%s%c", buffer, &newline); // get rid of the \n after the input
// you do the rest
}
The above code should print 27
#include <stdio.h>
void scan_hex(int *xptr)
{
char buffer[256];
char newline;
int i,j,k,sixteen=1;
*xptr = 0;
scanf("%s%c", buffer, &newline);
for(i=0;buffer[i]!='\0';i++);
for(j=i-1;j>=0;j--)
{
if(buffer[j]>='a' && buffer[j]<='f')
{
k = buffer[j] - 87;
// to covert a=10,b=11,c=12,d=13,e=15,f=15
// printf("%d\n",buffer[j]-87);
}
else
{
k = buffer[j] - 48;
//to covert char (1-9) to int(1-9)
// printf("%d\n",buffer[j]-48);
}
//this is to convert in base 16
//if a number is of the form a4,a3,a2,a1 then *xptr = a1*(16)^0 + a2*(16)^1 + a3*(16)^2 + a4*(16)^3
*xptr = *xptr + k * sixteen;
sixteen*=16;
}
}
void print_decimal(int x)
{
printf("%d\n",x);
}
int main()
{
int x;
scan_hex(&x);
print_decimal(x);
}
C program help 4. Write a function called scan_hex. Here is its prototype: void scan_hex(int *xptr);...
write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...
Code in C++: Please help me fix the error in function: void write_account(); //function to write record in binary file (NOTE: I able to store data to a txt file but however the data get error when I try to add on data the second time) void display_all(); //function to display all account details (NOTE: This function is to display all the info that save account.txt which is ID, Name, and Type) void modify_account(int); //function to modify record of file...
4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This function computes the number of appearances of each letter in the string word and stores them irn array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90 for the uppercase letters. You must account for uppercase and lowercase letter variants, which...
C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the class program with methods and variables 2. bill.cpp = contains the functions from class file 3. main.cpp = contains the main program. Please split this program into three files and make the program run. I have posted the code here. #include<iostream>...
The program needs to be written in C. Write a function void camelCase(char* word) where word consists of more than two words separated by underscore such as “random_word” or "hello_world_my_name_is_sam". camelCase() should remove underscores from the sentence and rewrite in lower camel case” (https:// en.wikipedia.org/wiki/Camel_case). Watch out for the end of the string, which is denoted by ‘\0’. You have to ensure that legal strings are given to the camelCase() function. The program should only run when the input is...
C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...
C programm , ´hello i need your help -Given the C program primes.c with the following main method: int main() { int num, res; char buffer[11]; bool finished = false; while (!finished) { printf("Enter n > 0 or quit\n"); scanf("%10s", buffer); if (strcmp(buffer, "quit") == 0) { finished = true; } else { // Convert input to number and compute n-th prime num = atoi(buffer); if (num > 0) { res = nth_prime(num); printf("Prime #%d is %d\n", num, res); }...
C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () { int numDucks,numCats; getInput(&numDucks, &numCats); // passing addresses of num1 & num2 to...
pUI) FOU are to write a function which has a prototype: void count (char sl, int *pUpper, "pLower, "poigit, pother) s [ is a character string which may be of any length. Other arguments are address of where the number of upper, lower, digits, and other characters in the string should be placed. For example (this is only an example) the code (put into a properly written program): char all "12145-9ABD, 3f0 :bbB2" char bll "148x3!!" char c[] = {...
Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...