Question: I need a code in C only, please. Do not change the template. Thanks The main purpose of this lab is to practice assigning/accessing pointers
I need a code in C only, please. Do not change the template. Thanks
The main purpose of this lab is to practice assigning/accessing pointers and printing address locations to the screen. We may build upon this functionality in a later lab.
The code template already has the functionality of prompting the user to enter a username that is at most 25 characters long. As always, leave the code in the template unmodified and simply add to it. Your programming tasks are to add the following functionality:
build an array of pointers to each character that is a not a letter (i.e. not an alpha character). This should be done in the function getPointers(), which takes in an array of chars, returns the number of non-alpha chars, and builds the array of points to each non-alpha char. See the code template for similar details on the input and output for the function.
back in main(), call getPointers(), print out a formatted message (see sample output below) with the username and the number of non-alpha characters. Finally, print out the non-alpha characters and their address locations (again, see the sample output below).
Sample Output
When the input is CS107@D1orSEL2249!, the output should be (note the address locations will be different in your output and could be different each time you run your program):
Enter a username: The username CS107@D1orSEL2249! has 10 non-alpha characters 1 is at address 0x7ffeefbff5e2 0 is at address 0x7ffeefbff5e3 7 is at address 0x7ffeefbff5e4 @ is at address 0x7ffeefbff5e5 1 is at address 0x7ffeefbff5e7 2 is at address 0x7ffeefbff5ed 2 is at address 0x7ffeefbff5ee 4 is at address 0x7ffeefbff5ef 9 is at address 0x7ffeefbff5f0 ! is at address 0x7ffeefbff5f1
#include
#define BUFFERSIZE 26 // 25 characters plus end of string
// [IN] charArray[]: array of chars // [OUT] *ptrsToChars[]: array of pointers to non-alpha chars in charArray // [OUT] returns number of non-alpha chars in charArray int getPointers(char charArray[], char *ptrsToChars[]){ return -1; }
int main() { char userInput[BUFFERSIZE]; char *ptrsToChars[BUFFERSIZE]; printf("Enter a username: "); scanf("%s",userInput); //End of template return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
