473,765 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MACRO to capitalize first letter of a word in header.

66 New Member
I know about toupper() and tolower() but I need to capitalize (or de-capitalize)the first letter of a word in a header file. I know there are no preprocessor functions that do that but is there another way?
Jan 7 '09 #1
12 12412
Banfa
9,065 Recognized Expert Moderator Expert
I think I would be forced to ask why? and over how many files?

For a small number of files then a text editor is probably your best bet.

For more files you might be able to use an awk script to automate a lot of the process or a perl script.

Ultimately you could write you own text processing program.
Jan 7 '09 #2
dissectcode
66 New Member
This would be done over 50 files, and they are needed to be capitalized in order to feed the word in the proper format, as an input into another macro.

I would like to keep this in a C header file.
Jan 7 '09 #3
donbock
2,426 Recognized Expert Top Contributor
I suggest you edit the header files to get the capitalization correct. You might have been able to alter 50 header files in the time since this thread was started.

How many different words do you need to alter? The following is a really bad idea ... suppose you only need to change "big" to "Big" and "Small" to "small"
Expand|Select|Wrap|Line Numbers
  1. #define big Big
  2. #define Small small
  3. ...
  4. #include <header>
  5. ...
  6. call the macros that use "big" and "Small"
  7. ...
  8. #undef big
  9. #undef Small
  10. ...
This is a bad idea because
1. There may be instances of "big" and "Small" that you don't want to change.
2. You are going out of your way to make your code hard for anybody to understand.
3. Corollary to #1 and #2 above ... someday you may modify the program to insert the word "big" or "Small" without any desire for it to be changed.
Jan 7 '09 #4
dissectcode
66 New Member
@donbock

This is definitely on the right track - to answer your question, I need to change to upper case, AND lower case in the same macro.

For example:

Expand|Select|Wrap|Line Numbers
  1. #define mac(name, val)  (Name *)(name->myMember.anum) = val
  2.  
See how name input is Name AND name in the macro?
Jan 7 '09 #5
donbock
2,426 Recognized Expert Top Contributor
@dissectcode
How about this ...
Expand|Select|Wrap|Line Numbers
  1.  
  2. typedef Name *ptr_name;
  3. ...
  4. #define mac(name, val) (ptr_##name)(name->myMember.anum) = val
  5.  
Jan 7 '09 #6
dissectcode
66 New Member
I need to change "name" to Name for the cast, and make sure it is in lower case for the structure name.

Also - "name" is arbitrary so I couldn't typedef it to one thing ?
Jan 7 '09 #7
donbock
2,426 Recognized Expert Top Contributor
What I meant was ... suppose you have three "names" (foo, bar, and squid) ... that means you want the following code to appear after all macro expansions:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Foo foo;
  3. Bar bar;
  4. Squid squid;
  5. ...
  6. (Foo *) (foo->myMember.anum) = fooVal;
  7. (Bar *) (bar->myMember.anum) = barVal;
  8. (Squid *) (squid->myMember.anum) = squidVal;
  9.  
My suggestion is to get the equivalent through the following ...
Expand|Select|Wrap|Line Numbers
  1.  
  2. typedef Foo *ptr_foo;
  3. typedef Bar *ptr_bar;
  4. typedef Squid *ptr_squid;
  5. ...
  6. #define mac(name, val) (ptr_ ## name)(name->myMember.anum) = val
  7. ...
  8. Foo foo;
  9. Bar bar;
  10. Squid squid;
  11. ...
  12. mac(foo, fooVal);
  13. mac(bar, barVal);
  14. mac(squid, squidVal);
  15.  
These macros expand into the three lines:
Expand|Select|Wrap|Line Numbers
  1.  
  2. (ptr_foo)(foo->myMember.anum) = fooVal;
  3. (ptr_bar)(bar->myMember.anum) = barVal;
  4. (ptr_squid)(squid->myMember.anum) = squidVal;
  5.  
Which, because of the typedefs, is equivalent to what you want.

I haven't tried this out on a compiler, so there might be syntax issues for you to work out, but I'm pretty sure the concept is valid.
Jan 8 '09 #8
dissectcode
66 New Member
@donbock

Thank you for your response. After looking through this code and concept - I am concerned that I cannot create a more general macro for any input during run-time....since it is a preprocessor thing, it does the concatenation at compile-time. Is this true?
Jan 8 '09 #9
Tassos Souris
152 New Member
Yes it is true.. this is done at compile time..

Can you give us a example of how you want this to work at run-time?
Jan 8 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1382
by: Colin Steadman | last post by:
Apoligies if this post appears twice, but my first attempt at posting it was hours ago and there is still no sign of it in the forum (says five minutes in the confirmation message). ============================================================================= I have some sample code from Microsoft that allows me to start a specific Word template at the click of a button from within an ASP page. I would like to modify this in such a...
3
23201
by: news.individual.net | last post by:
Hi! Can I capitalize the first letter of the first paragraph without using a special class for that <p> ? I tried it with this: body > p:first-child:first-letter { font-size: 270%;
3
5984
by: gil | last post by:
I have a script that will capitalize the first letter of every word in my descriptions. But some of my descriptions contain ( ) and /. For example bezel (black). I need the script to capitalize Bezel and (Black), but it is only finding the bezel and leaving the (black) in lower case. Here is the script below. Any help would be greatly appreciated. <SCRIPT LANGUAGE="JAVASCRIPT"> <!--
1
4121
by: Dwight Shubert | last post by:
Hi all, This is my first try using Access. I understand how to format a text field for uppercase and lowercase, but how do you capitalize only the first letter of each word? tia Dwight
5
8628
by: DDK | last post by:
What is the best way to capitalize the first letter of a string? Thanks for any help, d.
1
6281
blyxx86
by: blyxx86 | last post by:
I have the code to capitalize an entire string when it is input, but would like to capitalize just the first letter of a box, or match the case of a drop down list.. My current code is thus: Private Sub Serial_AfterUpdate() 'Makes serial field input all caps into database no matter what. Me.Serial = StrConv(Me.Serial, vbUpperCase) End Sub
8
4024
by: romo14 | last post by:
I'm working on a program that will take an address in on all one line separated by pounds (eg karen smith # p.o. box 123 # new york, new york #) and outputs it in user-friendly format. So far my program outputs: karen smith p.o. box 123 new york, new york The only thing I can't figure out how to do is to capitalize the words that need capitalization. I know I need to use the toupper function and I think a for loop, but I don't know how to...
7
16129
by: dizzylizzyd514 | last post by:
I need to make this: introductoRy speEch ==> Introductory Speech pRecalCulus 1 and 2 ==> Precalculus 1 And 2 I know how to capitalize the first letter of a word, but not multiple words in a string like the examples shown. Any ideas????
12
4001
by: jackson.rayne | last post by:
Hello, I am a javascript newbie and I'm stick at one place. I have a requirement where I will get a sentence in a variable example var v1 ="This is a sentence"
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9955
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.