Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

# Do the following problem- For assignment submission- use the format li (2).docx

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité

## Consultez-les par la suite

1 sur 1 Publicité

# Do the following problem- For assignment submission- use the format li (2).docx

Do the following problem. For assignment submission, use the format listed in the syllabus. Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the preceding character, and so on, until the entire string is reversed. Write a main program to test your function on various strings of both even and odd length.
Solution
#include #include #include int main(int argc, char* argv[]) { if (argc != 2) { printf(\"please specify exactly one argument, a string to reverse\ \"); exit(-1); } char* str = argv[1]; char a; char* front; char* rear; int len = strlen(str); front = str; rear = str + len - 1; printf(\"we will reverse the string %s in place\ \", str); while (front < rear) { a = *front; *front = *rear; *rear = a; front++; rear--; } printf(\"the reversed string is %s\ \", str); }
.

Do the following problem. For assignment submission, use the format listed in the syllabus. Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the preceding character, and so on, until the entire string is reversed. Write a main program to test your function on various strings of both even and odd length.
Solution
#include #include #include int main(int argc, char* argv[]) { if (argc != 2) { printf(\"please specify exactly one argument, a string to reverse\ \"); exit(-1); } char* str = argv[1]; char a; char* front; char* rear; int len = strlen(str); front = str; rear = str + len - 1; printf(\"we will reverse the string %s in place\ \", str); while (front < rear) { a = *front; *front = *rear; *rear = a; front++; rear--; } printf(\"the reversed string is %s\ \", str); }
.

Publicité
Publicité

## Plus De Contenu Connexe

Publicité

### Do the following problem- For assignment submission- use the format li (2).docx

1. 1. Do the following problem. For assignment submission, use the format listed in the syllabus. Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the preceding character, and so on, until the entire string is reversed. Write a main program to test your function on various strings of both even and odd length. Solution #include #include #include int main(int argc, char* argv[]) { if (argc != 2) { printf("please specify exactly one argument, a string to reverse "); exit(-1); } char* str = argv[1]; char a; char* front; char* rear; int len = strlen(str); front = str; rear = str + len - 1; printf("we will reverse the string %s in place ", str); while (front < rear) { a = *front; *front = *rear; *rear = a; front++; rear--; } printf("the reversed string is %s ", str); }