473,412 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

We are getting deeper and deeper of ctype.h and isspace() ,but no one is telling me ths solution !

Are there no genric Macros in c to represent Integers,Characters,...or
other data types ?
I want to pass that MACRO (representing an alpha numeric Character)to
that strrchar() function,to get the last occurence of the last NON
SPACE or Alphanumeric character,then i want to increase the position
by one and add a NULL char ....This is my IDEA of rtrim
function.....pls help me out.....

How can i get a way to represent genric alphanumeric charecters ?

Please help me.

Thanks in Advance.
regards,
Durgesh
Nov 14 '05 #1
5 2271

On Tue, 20 Dec 2004, Durgesh Sharma wrote:

Are there no genric Macros in c to represent Integers,Characters,...or
other data types ?
Data types correspond to sets of values that can be taken on by
variables or expressions. Macros, in C, are purely lexical constructs
with absolutely no "data type" from the language's point of view.
I want to pass that MACRO (representing an alpha numeric Character)to
that strrchar() function,
There is no such function in the C standard library.
to get the last occurence of the last NON
SPACE or Alphanumeric character,then i want to increase the position
by one and add a NULL char ....This is my IDEA of rtrim
function.....pls help me out.....
Do you mean to write

char *rtrim(char *buffer)
{
char *end = strchr(buffer, '\0');
while (end > buffer && isspace(end[-1])) --end; /* see [1] */
*end = '\0';
return buffer;
}

What's so hard about that?
How can i get a way to represent genric alphanumeric charecters ?


Please define "genric alphanumeric charecters," and tell us why you
want to "represent" them (it?). In other words, what are you /really/
trying to do?

-Arthur

[1] - Yes, pedantically speaking I hear it ought to be
while (end > buffer && isspace((unsigned char) end[-1])) --end;
But I hardly ever write the cast in practice. I suppose I'm limiting
the portability of my code to those implementations which do the Right
Thing when you pass a 'char' to the routines in <ctype.h>, but IMVHO
any implementation that doesn't do that is icky anyway. Add the cast
if you want. :)
(Maybe I ought to get in the habit of writing wrappers for the <ctype.h>
functions: #define is_space(x) isspace((unsigned char)(x)) and so forth.
....Maybe.)
Nov 14 '05 #2
On 20 Dec 2004 22:16:03 -0800, sh*******@yahoo.com (Durgesh Sharma)
wrote in comp.lang.c:
Are there no genric Macros in c to represent Integers,Characters,...or
other data types ?
I want to pass that MACRO (representing an alpha numeric Character)to
that strrchar() function,to get the last occurence of the last NON
SPACE or Alphanumeric character,then i want to increase the position
by one and add a NULL char ....This is my IDEA of rtrim
function.....pls help me out.....

How can i get a way to represent genric alphanumeric charecters ?

Please help me.

Thanks in Advance.
regards,
Durgesh


I gave you a perfectly good answer, with useable code, when you first
asked this question on December 4.

Since then you spammed the group for a gmail invitation.

*plonk*

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #3
>Are there no genric Macros in c to represent Integers,Characters,...or
other data types ?
No, and what does this question have to do with what follows?
I want to pass that MACRO (representing an alpha numeric Character)to
that strrchar() function,to get the last occurence of the last NON
C does not have a function strrchar().
C does have a function strrchr(). The second argument takes a
specific (not generic, whatever a generic character would be)
character cast to an int.
SPACE or Alphanumeric character,then i want to increase the position
by one and add a NULL char ....This is my IDEA of rtrim
function.....pls help me out.....
Trying to use strrchr() for an rtrim function is a lot like
using a screwdriver to remove nails: it's the wrong tool for
the job. strrchr() scans for the last occurrence of a specific
character, not a generic character (whatever that is).
How can i get a way to represent genric alphanumeric charecters ?
Regardless of how you represent them, strrchr() won't accept
them. ANSI C does not have regular expressions. And even if
you use one of the ways of representing regular expressions
(say "[A-Za-z0-9]*"), strrchr() doesn't take a string for
its second argument.
Please help me.


Hint: loop over each character of the string. If it's NOT one of
the characters you want to trim off (the <ctype.h> functions may
be helpful here), save this position. After the loop exits, the
last saved position points at the last character you wish to keep.
Now, think about what you want to happen if NONE of the characters
you want to keep (the string is all blanks). Also, what is supposed
to happen if the string ends in a non-space, non-alphanumeric
character (say, a period, comma, colon, question mark, or asterisk)?

Gordon L. Burditt
Nov 14 '05 #4
Durgesh Sharma wrote:
Are there no genric Macros in c to represent Integers,Characters,...or
other data types ?
If you mean a sort of regex for characters, then the answer is no.
I want to pass that MACRO (representing an alpha numeric Character)to
that strrchar() function,to get the last occurence of the last NON
SPACE or Alphanumeric character,then i want to increase the position
by one and add a NULL char ....This is my IDEA of rtrim
function.....pls help me out.....
In fact, you want a sort of strrspn function. Alas, there isn't one.
But it would be quite easy to write.

Or you could define an array of UCHAR_MAX + 1 ints, with each one
set to either 1 or 0 (or, perhaps, you could bitmap them into various
categories such as digit, hexit, alpha, lower, upper, etc), and then
write your own macros. In fact, that's quite a neat idea.
How can i get a way to represent genric alphanumeric charecters ?


Develop one.
Nov 14 '05 #5
Durgesh Sharma wrote:
Are there no genric Macros in C
to represent Integers,Characters,...or other data types?
No.
I want to pass that MACRO (representing an alpha numeric Character)to
that strrchar() function,to get the last occurence of the last NON
SPACE or Alphanumeric character, then I want to increase the position
by one and add a NULL char ....This is my IDEA of rtrim
function.....pls help me out.....

How can I get a way to represent genric alphanumeric charecters?
You can't.
Please help me. cat rtrim.c

#include <ctype.h>
#include <string.h>

char* rtrim(char* s) {
const
size_t n = strlen(s);
size_t j = n;
while ((0 < j) && isspace(s[j-1]))
--j;
s[j] = '\0';
return s;
}
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff Fulcer | last post by:
I am trying to do a get/post with a certificate to another server to gather information. I was provided with an ASP example that I am able to get my results fine with, but when I try it in .NET,...
6
by: Brett | last post by:
Not sure what the problem is here... Trying to update from a datagrid to an access database using vb.net... Its not updating the database but Im not getting any errors... Here is my code... ...
22
by: Mike Polinske | last post by:
I am new to the C programming language but have been programming in Cobol for over 10 years. When I compile the following code, it compiles clean but I get an application error both under Windows...
6
by: Bill foust | last post by:
I'm running into a situation there I think an operator overload would solve the issue, but I'm unable to make it work for some reason. If anyone can help here I would appreciate it. I have a...
2
by: bearophileHUGS | last post by:
Are you using the str.isspace() method? I don't use it, so if most people don't uses it, then it may be removed from Py 3.0. I usually need to know if a string contains some non-spaces (not space...
2
by: Adrian | last post by:
Hi All, Is there anyway to change what isspace thinks is a space character. I am parsing some log files and it would be nice to just read a field as what ever is between quotes or between 's ie...
7
by: Army1987 | last post by:
Does the Standard forbid isspace(0) from returning 1 in any locale? Is it possible that in some locales the loop for (cursor = nptr; isspace((unsigned char)*cursor); cursor++) continue; slips off...
1
by: kenneth6 | last post by:
ctype.h: toupper(c), tolower(c): change case of char isalphanum(c), isalpha(c), isdigit(c), ispunct(c), isspace(c), iscntrl(c), islower(c), isupper(c): boolean checks on type of char i know...
8
by: Joe HM | last post by:
Hello - I was wondering that the "cleanest" way is to determine whether a CType() will throw an InvalidCastException? I have data I receive as an Object and I want to convert it to a String...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.