473,394 Members | 1,867 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,394 software developers and data experts.

question about string

Can you please give some example?? I beening trying to do that, but i
am having no idea how do i start.
Thx for help.
"S.Tobias" <si***@FamOuS.BedBuG.pAlS.INVALID> wrote in message news:<3c*************@individual.net>...
Momo <mo********@gmail.com> wrote:
I have like a string here say: "PROGRAM= sample"
how do i extract this string value so that i can have like
"sample"(notice no space infront of sample) standalone as a char
itself.
any help will be good


You can set a char pointer to the beginning of the string, then
strchr for '=', if successful, increase the pointer, skip spaces
(or all white-space, you can use isspace() for that).

Nov 14 '05 #1
1 984
Momo wrote:
Can you please give some example?? I beening trying to do that, but i
am having no idea how do i start.
Thx for help.

See Below.
Momo <mo********@gmail.com> wrote:
I have like a string here say: "PROGRAM= sample"
how do i extract this string value so that i can have like
"sample"(notice no space infront of sample) standalone as a char
itself.
any help will be good

You can set a char pointer to the beginning of the string, then
strchr for '=', if successful, increase the pointer, skip spaces
(or all white-space, you can use isspace() for that).

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

char *RemoveLeadingWP(char *s);
char *RemoveTrailingWP(char *s);
char *ParseData(char *s);

int main(void)
{
char *result, test[64] = "PROGRAM= A string without leading "
"and trailing Whitespace ";

result = ParseData(test);
if(result)
printf("Parsed string is: \"%s\"\n",result);
return 0;
}

char *RemoveLeadingWP(char *s)
{
char *s1;

for(s1 = s; *s1 != '\0'; s1++)
if(!isspace((unsigned char)*s1)) break;
if(s1 != s) memmove(s,s1,strlen(s1)+1);
return s;
}

char *RemoveTrailingWP(char *s)
{
char *endp;

for(endp = s+strlen(s); endp!=s; endp-- )
if(!isspace((unsigned char)*(endp-1))) break;
*endp = '\0';
return s;
}

char *ParseData(char *s)
{
char *s1;

if((s1 = strrchr(s,'=')) != NULL)
{
RemoveTrailingWP(++s1);
RemoveLeadingWP(s1);
return s1;
}
return NULL;
}
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapidsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #2

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

Similar topics

1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
16
by: dario | last post by:
Hi, Im new on phyton programming. On my GPRS modem with embedded Phyton 1.5.2+ version, I have to receive a string from serial port and after send this one enclosed in an e-mail. All OK if the...
5
by: John Baro | last post by:
I have a richtextbox which I want the "literal" rtf of. richtextbox.rtf returns {\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0 when i put this into a string I get...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
15
by: DV | last post by:
I have a StringBuilder that has a string with 12,000,000 characters. When I do a ToString(), I expect to have ~25,000,000 bytes worth of memory, yet, I end up with ~43,000,000 bytes. That's...
6
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public...
6
by: RSH | last post by:
I am still trying to grasp the use of real world Objects and how to conceptualize them using a business scenerio. What I have below is an outline that I am wrestling with trying to figure out a...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
29
by: Amar Kumar Dubedy | last post by:
implement a c++ class such that it allows us to add data members at runtime.
2
by: robtyketto | last post by:
Greetings, Within my jsp I have HTML code (see below) which accepts input, one of these fields sequence unlike the others is an Integer. <FORM ACTION="wk465682AddFAQ.jsp" METHOD="POST"> Id:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.