Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a. Write a function in C that takes an array of char and a char ** expression as

ID: 3621862 • Letter: A

Question

a. Write a function in C that takes an array of char and a char ** expression as parameters. The array of type char would contain a string the possibly starts with a sequence of decimal digits. Have the function convert the sequence of decimal digits it finds to type int and return the converted value. Have the function set the contents of its second parameter (a char * value) to point to the first character in the array that was not converted. For example, if the function was called convert () and the call to convert () was
intval = convert (array, & charptr);
where array contained the string
2 7 4 A D A M S

then after the call, intval would contain the 274, and charptr would point to the ‘A’ in the string.

Explanation / Answer

Dear, charPtr contains 'A' Here is the code #include #include int convert(char array[],char *ptr); void main() { char array[]="274ADAMS"; char charPtr=array[0]; //function call int intVal=convert(array,&charPtr); printf("Value=%d %c",intVal,charPtr); system("pause"); } int convert(char array[],char *ptr) { int i=0,value=0; while(array[i]!='') { if(isalpha(array[i])) { *ptr=array[i]; break;} i++; } if (isdigit(array[0])) value = atoi (array); return value; }Hope this will help you
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote