Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1039731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:08:11+00:00 2026-05-16T15:08:11+00:00

I am using Linux. I am trying to write a program in c that

  • 0

I am using Linux.
I am trying to write a program in c that will print a string backward.
Here is my code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (){
    char string[100];
    printf ("Enter string:\n");
    gets (string);
    int length = strlen (string)-1;
    for (length = length; length>=0; length--){
        puts (string[length]);
    }
}

And here is the error:

a.c:10: warning: passing argument 1 of ‘puts’ makes pointer from integer without a cast
/usr/include/stdio.h:668: note: expected ‘const char *’ but argument is of type ‘char’
/tmp/cc5rpeG7.o: In function `main':
a.c:(.text+0x29): warning: the `gets' function is dangerous and should not be used.

What should I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:08:12+00:00Added an answer on May 16, 2026 at 3:08 pm

    First:

    NEVER NEVER NEVER NEVER NEVER use gets(); it will introduce a point of failure in your code. There’s no way to tell gets() how big the target buffer is, so if you pass a buffer sized to hold 10 characters and there’s 100 characters in the input stream, gets() will happily store those extra 90 characters in the memory beyond the end of your buffer, potentially clobbering something important. Buffer overruns are an easy malware exploit; the Morris worm specifically exploited a gets() call in sendmail.

    Use fgets() instead; it allows you to specify the maximum number of characters to read from the input stream. However, unlike gets(), fgets() will save the terminating newline character to the buffer if there’s room for it, so you have to account for that:

    char string[100]; 
    char *newline;
    printf("Enter a string: ");
    fflush(stdout);
    fgets(string, sizeof string, stdin);
    newline = strchr(buffer, '\n');      // search for the newline character
    if (newline)                         // if it's present
      *newline = 0;                      // set it to zero
    

    Now that’s out of the way…

    Your error is coming from the fact that puts() expects an argument of type char *, but you’re passing an argument of type char, hence the “pointer from integer without cast” message (char is an integral type). To write a single character to stdout, use putchar() or fputc().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to write a program in java (on linux) using RandomAccessFile class
I'm trying to write a C program to change a user password using Linux
I'm using read/write locks on Linux and I've found that trying to upgrade a
I am trying to compile code that works on os x and linux using
I am trying to write a simple program that prints out a C string
I'm trying to write a program that will fetch data from a SQL Server
I'm trying to write a rather trivial program using open gl on linux, but
I'm trying to write a cross-platform program in c++ that will load certain modules
Im trying to parse the string located in /proc/stat in a linux filesystem using
I'm trying to write a secure transfer file program using Python and AES and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.