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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:00:48+00:00 2026-06-18T12:00:48+00:00

When I compile this using GCC on linux, as I am waiting for input,

  • 0

When I compile this using GCC on linux, as I am waiting for input, the “hi” shows up. I do not want to use scanf, and want to know why the hi is showing while I am asking the user to input the name. Also when I want to printout the name of the file that was just passed, I get garbage characters. In netbeans, i get what I want. but on linux, it decides to act weirdly. please help

Code:

int main(int argc, char** argv)
{
char val[70];
        if(write(1, "Please input your name", 36)!=36)
        {
                return -1;
        }
        if(read(0, val, 36) < 0)
        {}

        if(write(1, val, 36)!=36)
        {}

printf("Yo");//THIS IS PRINTING OUT WAY BEFORE IT IS CALLED, ANY VARIABLE WITH A STRING     GETS PRINTED OUT, EVEN WITHOUT PRINTF BEING INVOKED
}

output:

Please input the file nameYo: hi
hi
???Om?0?a?Sm?  <<WHAT IS THIS? I DONT GET THIS ON NETBEANS
  • 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-06-18T12:00:49+00:00Added an answer on June 18, 2026 at 12:00 pm

    The third argument to write is the byte length of the string you’re trying to print. You have 36, but the string you provide is only 22 bytes long. Changing the code to look like the following will behave as you expected it to:

    int main(int argc, char** argv)
    {
        char val[70];
        if(write(1, "Please input your name", 22)!=22)
        {
            return -1;
        }
        if(read(0, val, 36) < 0)
        {}
    
        if(write(1, val, 36)!=36)
        {}
    
        printf("Yo");//THIS IS PRINTING OUT WAY BEFORE IT IS CALLED, ANY VARIABLE WITH A STRING     GETS PRINTED OUT, EVEN WITHOUT PRINTF BEING INVOKED
    }
    

    Note that you should probably look into using printf and scanf so that you wont have to worry about byte lengths so much.

    That might look like this:

    #include <stdio.h>
    
    int main(int argc, char** argv)
    {
        char val[70];
        printf("Please input your name");
    
        if(scanf("%69s", &val) == 1)
            printf(val);
    
        printf("Yo");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have compiled my application on Linux (Intel) machine using this command gcc –g
I am trying to compile the following code on Linux using gcc 4.2: #include
I'm writing a program in c on linux using gcc. If I'm not using
When trying to compile this code: #include <iostream> #include <vector> using namespace std; class
I'm using this code to create multiple functions wrappers using variadic templates: // Compile
I have a problem - i can't compile SqlCipher. I'm using this http://groups.google.com/group/sqlcipher/browse_thread/thread/55c6296b56bf4533/c792bbec6df7d4f4?tvc=2#c792bbec6df7d4f4 instructions
How can I get this to compile? The error is when I start using
Having this errors when trying to compile/run my app using Maven. I've succeeded to
I am using vala. This is the source code that gives that compile time
I'm following this guide mostly to compile gcc on windows: http://www.aristeia.com/Misc/gcc4ForWindows.html The difference is

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.