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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:57:14+00:00 2026-06-12T20:57:14+00:00

This is my first post, so if I’m being too vague or giving information

  • 0

This is my first post, so if I’m being too vague or giving information that everyone would intuitively assume, please let me know.

I’m very new to writing in C and am just trying to get a better understanding of preprocessing. I’m writing a simple program that can take in arguments either directly from the console using gcc -Wall -std=c99 -DSEED=argument, where my argument should be a an integer, or if the -D is not defined the user will input it.

The SEED value is simply used in srand(). I’m very confused why my code will not compile if I put in an -DSEED=a as my argument while if I put -DSEED=1 it will compile. I’m getting a “âaâ undeclared (first use in this function)” error and really don’t understand the difference between the two. I thought the #define matched up the variable type with the input, so if I put in an “a” #SEED would be a char and if I put in a “1” #SEED would be an int.

If the SEED is not defined I’m using a #ifndef SEED command and this works well.
I think I’m supposed to “stringify” the input SEED and then can check if it is an integer or not. After reading some articles online I’m trying to use:

#ifndef SEED
    //code
#else
    #define TO_STRING( input ) #input
    char c;
    c = TO_STRING( SEED )
    //Then I was going to use c to figure out if it was an int.
#endif

This is not working and anyone able to point out any misconceptions that you think that I may have would be greatly appreciated.

EDIT – So I did figure out why I was receiving the error message when trying the -DSEED=a, because it was reading it as a variable.

  • 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-12T20:57:15+00:00Added an answer on June 12, 2026 at 8:57 pm

    To stringify a #define you need to use a two-step approach:

    #define _STRINGIFY(s) #s
    #define STRINGIFY(s) _STRINGIFY(s)
    
    ...
    
    #define SEED 123
    
    ...
    
    const char * pszSeed = STRINGIFY(SEED); /* 'pszSeed' would point to "123" form here on. */
    

    If you only want to use one character simply access it via *pszSeed or pszSeed[0].

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

Sidebar

Related Questions

This is my first post after being a long-time lurker - so please be
This is my first post in this forum, so please, be patient with me.
This is my first post on stackoverflow, so please excuse me if my question
This is my first post on Stack, so please bear with me if I
This is my first post so please go easy on me fellas. I am
This is my first post on this forum (so please be gentle ) I'm
This is my first post to Stack Overflow so please forgive me if I
This is my first post, so please go easy on me if I say
this is my first post here. I'm using an existing Flash widget but would
This is my first post, so please be nice :) I have a question

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.