The following example shows how to call the system service to read in a string o
ID: 655208 • Letter: T
Question
The following example shows how to call the system service to read in a string of characters from the keyboard.
.data
buffer: .space 60 #Allocate n bytes of space in the data segment
main:
li $v0, 8 #system call code Read String
la $a0, buffer #$a0 is a pointer to an input buffer
li $a1, 60 #specifies the maximum length of input buffer
syscall
Program
Write a C program that will read in a string of characters (60 characters or less) and will print out the string in reverse. For example the string
Explanation / Answer
#include<stdio.h>
#include<string.h>
int main() {
char str[100], temp;
int i, j = 0;
printf(" Enter the string :");
gets(str);
i = 0;
j = strlen(str) - 1;
while (i < j) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
}
printf(" Reverse string is :%s", str);
return (0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.