Question

Write the following (Saved as linex.c). It must compile successfully using:    gcc --std=c99 linex.c -o linex...

Write the following (Saved as linex.c).
It must compile successfully using:
   gcc --std=c99 linex.c -o linex

(I have tried using 'gets' method which failed to compile said 'gets' is deprecated, so 'gets' may not be suitable for me, please provide me with alternative codes which can be compiled with c99)

It will read a single line of text from standard input.
It will print "R=" followed by that line backwards and then exit with status 0.

eg:

./linex
123456

would output
R=654321

Notes:
   i) your program must not leak memory or perform any invalid memory accesses.
   ii) your program should not use more memory than it needs.
   iii) do not call fgets or getline

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

Code :-

#include <stdio.h>
#include <string.h>


int main(void){
// Your code here!
char a[10];
int leng=0,g=0;
scanf("%[^\n]",a);
leng = strlen(a);

//print character from end//
printf("R=");
for(g = leng - 1; g >= 0; g--) {
printf("%c", a[g]);
}
}

output:-


Add a comment
Know the answer?
Add Answer to:
Write the following (Saved as linex.c). It must compile successfully using:    gcc --std=c99 linex.c -o linex...
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
  • A. File I/O using C library functions File I/O in C is achieved using a file...

    A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...

  • // CSE240 Spring 2019 HW 7 & 8 // Write your name here // Write the...

    // CSE240 Spring 2019 HW 7 & 8 // Write your name here // Write the compiler used: Visual studio or gcc // READ BEFORE YOU START: // You are given a partially completed program that creates a linked list of patient information. // The global linked list 'list' is a list of patients with each node being struct 'patientList'. // 'patientList' consists of struct 'patient' which has: patient name, room number, and a linked list of 'doctors'. // The...

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