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 5964023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:21:27+00:00 2026-05-22T19:21:27+00:00

I need to read a number of unsigned character from the input(ASCII value>127). SO

  • 0

I need to read a number of unsigned character from the input(ASCII value>127).
SO i used-

unsigned char S[102];

but when i take input like this-

 gets(S);

compiler show error:

error: invalid conversion from
‘unsigned char*’ to ‘char*’

So my question is how read unsigned character array using gets() or any other function exist.

  • 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-22T19:21:27+00:00Added an answer on May 22, 2026 at 7:21 pm

    First, you should never use gets. It cannot be used safely under any circumstances. My comment may have been a bit hyperbolic for humorous effect, but the point still stands.

    The function you should use instead of gets is fgets. fgets takes a FILE * pointer (but you’ll probably just want to pass stdin) and a maximum length, so it knows not to overflow your buffer. Unlike gets, fgets isn’t guaranteed to read in an entire line – the line might be too big for your buffer to hold. You can, however, easily recover from this and write code to correctly process the input in a variety of ways (whereas with gets you just have to hope your buffer is long enough, and if it’s not, who knows what will happen.)

    I’m a little unclear on what kind of data you intend to read. If it’s text, fgets is probably what you’re looking for. It still takes a char *, so to make this work you’ll need to cast S to a char * when you pass it to the function. Normally casts are a bad thing, especially casts from signed to unsigned types, but in this case nothing bad will (likely) happen.

    If you’re actually reading binary data into your unsigned array, you should look into fread. Unlike fgets it takes a void * to accommodate whatever kind of data you need to read, so no cast will be necessary. Note that fread reads chunks rather than lines, so if you’re wanting textual input you should look elsewhere – it won’t try to read an entire line, nor will it stop reading into a buffer when it sees a line ending.

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

Sidebar

Related Questions

I need to read 16 bits from the binary file as std::string or char
I need to read fixed number of bytes from files, whose sizes are around
I need to read a byte array of 16 bits as unsigned short number,
I have a file named input.in. I need to read the number and store
I need to read a large list of integers from a file but as
I need to read a number of arrays from a file and print them.
I need to read account number from Maestro/Mastercard with smart card reader. I am
Hi I need an script to read number of eth interrupts from the /proc/interrupts
I need to read certain statistics from iw_statistics structure, here's the code: struct net_device
I need to read data from XML to a List<>. The XML file contains

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.