How do I make a greeting a named constant rather than a literal constant?

Recommended Answers

All 3 Replies

rather than

printf("Greetings!\n");

You could use:

const char* greeting = "Greetings!\n";

printf( greeting );

How do I make a greeting a named constant rather than a literal constant?

I'm not sure if I completely understand what you are asking.

#include <stdio.h>
 
 int main( void )
 {
    const char named_constant[] = "string literal initializer";
    puts("literal constant"); /* (1) */
    puts(named_constant); /* (2) */
    return 0;
 }
 
 /* my output
 literal constant
 string literal initializer
 */

Are you asking how to do (2) instead of (1)?

How do I make a greeting a named constant rather than a literal constant?

cford,

Welcome to TechTalkForums. In the future, please name your thread something meaningful. "HEELLLPPPP!!!! Due Tomorrow 9-14-04" doesn't tell us anything about what you need. "Making a named constant", or something similar would have been more appropriate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.