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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:57:48+00:00 2026-06-13T18:57:48+00:00

First,I have to say that I am new to C programming. What I’m trying

  • 0

First,I have to say that I am new to C programming. What I’m trying to do is write a program that takes an argument input and converts it into an integer and then returns its value. My code looks like this:

#include <stdio.h>
#include <stdlib.h>

int main (int argc, char *argv[])
{
   int fromArgv = NULL;  /* holds value from argv[1] */
   fromArgv = atoi (argv[1]);    /* convert argv[1] to int */

   /* if incorrect no. of arguments entered */
   if (argc != 2) {
   fprintf (stderr, "error: wrong number of arguments\n");
   exit (EXIT_FAILURE);
   } 

   return fromArgv;
}

I get the following error when trying to compile:

ex1.c: In function ‘main’:
ex1.c:6:18: error: initialization makes integer from pointer without a cast [-Werror]
cc1: all warnings being treated as errors
  • 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-13T18:57:50+00:00Added an answer on June 13, 2026 at 6:57 pm

    Your problem is the line

    int fromArgv = NULL; 
    

    I believe NULL is usually defined as (void *) 0, which is a pointer. You’re assigning this pointer to an int variable, which gives you the error.

    However, there’s no need to initialize fromArgv in this case. You can just do:

    int fromArgv;  /* holds value from argv[1] */
    fromArgv = atoi (argv[1]);    /* convert argv[1] to int */
    

    or even just

    int fromArgv = atoi (argv[1]);    /* convert argv[1] to int */
    

    What you do have to do, however, is make sure argv[1] exists before you access it so you don’t get a segfault if the user does not enter any command-line arguments. You should move your if (argc != 2) test before the assignment of fromArgv.

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

Sidebar

Related Questions

First of all, I have to say that I'm going to talk about System.ComponentModel.Component
At first, i have to say that this topic is very common topic. I
First of all i want to say that i have searched each and every
First off I should say that I don't have any experience in working with
First, let me just say that I have searched for information on this topic;
Let's say I have a form that collects a first name and a last
First of all I have to say I am new to iOS development. My
I first have to say that I really am a rookie in caching, so
First let me say that I am new to C so my approach is
First I need to say that I am new to iPhone development, so please

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.