• C

Preprocessor, use for #define is to give symbolic names to string constants

One common use for #define is to give symbolic names to string constants. After encountering

#define  DIGITS    "0123456789"
#define  LOWERS    "abcdefghijklmnopqrstuvwxyz"

the preprocessor replaces each occurrence of DIGITS with string constant "0123456789" and each occurrence of LOWERS with string constant "abcdefghijklmnopqrstuvwxyz". Define a separate header file that contains definitions of some of the more common strings we’re likely to use (ex UPPERS for upper case letters, PUNCTUS for  ,.;:!? ,  QUOTES for  ‘ ” and  BRACKETS  for  ( ){ }[ ]. Write a program that reads a sequence of characters. The program should count the various types of characters and print them. Include the header file in your source code file.
tom41982Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mayank SAssociate Director - Product EngineeringCommented:
We're not here to do your homework for you. If you wish, we can help you out with a few hints as to how to proceed with the problem.

Mayank.
0
KocilCommented:
Usually we ask a student to do his/her best shoot, the we will make the correction. This time, I'll give you the skeletons, you finish the rest by your self.


/* Define a separate header file that contains definitions of some of the more common strings were likely to use (ex UPPERS for upper case letters, PUNCTUS for  ,.;:!? ,  QUOTES for    and  BRACKETS  for  ( ){ }[ ]. */

// First step. create a new file named pre.h
#ifndef PRE_H
#define PRE_H

// define your constants here
#define TYPE1  "value"
#define TYPE2  "value"

#endif


/* Write a program that reads a sequence of characters. The program should count the various types of characters and print them. */
/* Include the header file in your source code file. */


// Second step
// create create a new file, name it pre.c

// Include the header file
#include "pre.h"


main()
{
   char sequences[100];
   
   // read the sequences

   // count the sequence type

}


OK ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jmcgOwnerCommented:
I'm wondering what the real intent of this homework problem is. The intro correctly points out that using defines like this replaces each occurrence of the SYMBOL with a copy of the string that was defined ... but it leaves open the question of whether you want each occurrence of the symbol to be a separate instance of the string or if you'd prefer that all of the occurrences re-use the same storage space, since, at least in these examples, the strings are constants. Normally, when writing larger programs, such considerations come into play and, since it's undesirable to allocated storage and initialize variables in a header file, you often would need a .c file corresponding to the .h file which can do these things and which is compiled and loaded with the program that's using the header file.
0
Choose an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program was designed in collaboration with national intelligence organizations and IT industry leaders.

tom41982Author Commented:
Thanks for the skeletons that you gives me..
you have a great day^^
0
KocilCommented:
> I'm wondering what the real intent of this homework problem is.

Have you ever know any assignment that have real purpose except to make grade A, B, C, D, or E ?
 
0
jmcgOwnerCommented:
It's been a long time since I was teaching, but when I made up a problem, I tried to make ones that did not teach things that would later have to be unlearned.
0
KocilCommented:
Well, older teacher is wiser.
In many cases, computer assignment is made by senior students.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.