Question

C Question: Write a function p3 which receives a C string as a parameter, and an...

C Question:

Write a function p3 which receives a C string as a parameter, and an array of integers which will serve as indices into the string. The third parameter is the length of the integer array. The function jumbles the characters in the string according to the indices in the array of numbers. For example:

char course [] = "CSC 373 Computer Systems I"; int indices[ ] = {0,1,4,5,6,7,0,1,25};

Then the function call p3(course, indices, 9);

would cause course to contain “CS373 CSI” (with garbage after the new ‘\0’ character)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

#include<stdio.h>

void p3(char *, int *, int len);

int main(){

char course[] = "CSC 373 Computer Systems I";

int indices[] = {0,1,4,5,6,7,0,1,25};

p3(course, indices, 9);

return 0;

}

void p3(char course[], int indices[], int len){

int i;

char s[50];

for(i=0; i<len; i++){

s[i] = course[indices[i]];

}

s[i] = '\0';

printf("%s\n", s);

}

Add a comment
Know the answer?
Add Answer to:
C Question: Write a function p3 which receives a C string as a parameter, and an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    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,...

  • Write a C function that receives a character array (string), and it will check the characters...

    Write a C function that receives a character array (string), and it will check the characters of the array to figure out whether the string has a given valid pattern. The required pattern will be given to you. In this function, for instance, you should check if the ascii code of an element of the character array is between a range. The ascii table of all the printable characters will be provided to you. See the last page of this...

  • Write in C language 5. [8] Write a function with prototype » void string_copy(const char source[],...

    Write in C language 5. [8] Write a function with prototype » void string_copy(const char source[], char destination[], int n); This function copies string source to string destination. Parameter n represents the size of array destination. If the latter array is not sufficiently large to hold the whole source string then only the prefix of the string which has room in the latter array should be copied. Note that after copying, the null character should also be included to mark...

  • Define a function called repeat_middle which receives as parameter one string (with at least one character),...

    Define a function called repeat_middle which receives as parameter one string (with at least one character), and it should return a new string which will have the middle character/s in the string repeated as many times as the length of the input (original) string. Notice that if the original string has an odd number of characters there is only one middle character. If, on the other hand, if the original string has an even number of characters then there will...

  • Write a function getScores(...) that is given a string, an int type array to fill and...

    Write a function getScores(...) that is given a string, an int type array to fill and the max number of elements in the array as parameters and returns an integer result. The function will find each substring of the given string separated by space characters and place it in the array. The function returns the number of integers extracted. For example: int values[3]; getScores("123 456 789", values, 3 ); would return the count of 3 and fill the array with...

  • 4. Write a C function int str2int(char *s) that takes string s as parameter and return...

    4. Write a C function int str2int(char *s) that takes string s as parameter and return the integer that s represents. For example, if string s is 123", then the function return integer 123.

  • Can you help me make these two methods listed below work? I have code written but...

    Can you help me make these two methods listed below work? I have code written but it is not working. I would appreciate any advice or help. Function "isAPalidrome" accepts an array of characters and returns an integer. You must use pointer operations only, no arrays. This function should return 1 (true) if the parameter 'string' is a palindrome, or 0 (false) if 'string' is not a palindrome. A palindrome is a sequence of characters which when reversed, is the...

  • PYTHON 1- Write a function that receives a string value as a parameter, converts its first...

    PYTHON 1- Write a function that receives a string value as a parameter, converts its first character to uppercase and returns the first character. 2- Test your function by writing a main, which calls your function and prints its return value. 3- Save your program in a file called firstChar.py and use the following link to submit your file.  

  • In the space below, write a C function definition for a function named StrLower, which will...

    In the space below, write a C function definition for a function named StrLower, which will receive one parameter, a pointer to a null-terminated string (i.e., pointer to char), convert each character in the string to lowercase (using the tolower function from <ctype.h>), and return nothing to the caller. Inside the function definition, you may use a for loop or a while loop. If you use any variables other than the incoming parameter, you must define them locally in the...

  • Write a function that takes an array of C-strings as a parameter and the number of...

    Write a function that takes an array of C-strings as a parameter and the number of elements currently stored in the array, and returns a single C-string pointer that is the concatenation of all C-strings in the array. Note: The function must take 2 parameters and return "char *". Any other ways will cause some deduction of points.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT