473,763 Members | 9,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trim Left char tchar[64]

I read a text file into a char variable

char tchar[64];

I want to trim leading spaces (Left trim).How can I do that in C++.
Any input will be appreciated.

Jul 23 '05 #1
4 4623
You're probably better of using stl strings, and then you have to write
some code as in this link for example
http://www.experts-exchange.com/Prog..._21282559.html

Jul 23 '05 #2
hi,

Thanks for the response

Murugan

Jul 23 '05 #3

<mu******@gmail .com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I read a text file into a char variable

char tchar[64];

I want to trim leading spaces (Left trim).How can I do that in C++.
Any input will be appreciated.


#include <algorithm>
#include <iostream>
#include <string>

void trimleft(char *arr)
{
std::string s(arr);
std::string::si ze_type pos(s.find_firs t_not_of(" "));

if(pos != std::string::np os)
{
s.erase(0, pos);
s += '\0';
std::copy(s.beg in(), s.end(), arr);
}
else
*arr = 0;

}

void show(char *arr, const char *prefix = "")
{
std::cout << prefix << '[' << arr << ']' << '\n';
}

int main()
{
char tchar[64] = " Hello world ";

show(tchar, "Before:\n" );
std::cout.put(' \n');

trimleft(tchar) ;
show(tchar, "After:\n") ;
return 0;
}

-Mike
Jul 23 '05 #4
Thanks Mike ,It worked like a charm

Jul 23 '05 #5

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

Similar topics

3
8012
by: Q. John Chen | last post by:
It should be easy but I am not familier with javascript. I have a string that is encoded simply by replacing the letter with the next letter in the alphabeta. I need a function to convert it back. Following is the function: function cnvtBack(encoded) { var orig = ""; for (i=0; i < encoded.length; i++)
11
2694
by: Allan Bruce | last post by:
Hi there, I have a stuct which requires a char (I cant change it as it is part of the win32 api), but I have a const char * pointing to a string literal declared as: WCS->AppName = "Some Text"; Appname is a const char *. How do I convert from this to the char required for the struct?
0
264
by: joye | last post by:
Hello , I meet some data convertion problem, the sample code as following, namespace Configure { using namespace System ; typedef struct _SW{ char szVersion ;
1
2157
by: joye | last post by:
Hello , I meet some data convertion problem, the sample code as following, namespace Configure { using namespace System ; typedef struct _SW{ char szVersion ;
3
2209
by: MX | last post by:
Welcome! I have something like that: ref class DCAM { ... private: char str; ...
4
9792
by: Gon | last post by:
Hello, Can some one help me out how to rewrite the below line to avoid errors/warings on a windows 64-bit platform? char *new_string = (char *) malloc (strlen (old_string) + 1); "argument' : conversion from 'size_t' to 'unsigned int', possible loss of data" is the warning I am getting.
5
3199
by: Amit_Basnak | last post by:
Dear Friends I have been getting the following error Error 185: "WorkFlow_dce.cpp", line 58 # Left side of '->' requires a pointer to class; type found was 'struct WF_SEARCH_WU'. lclStruct->wfWuHandle.workunitId =(long) feStruct->wfWuHandle- ^^^^^^^^ Error 185: "WorkFlow_dce.cpp", line 59 # Left side of '->' requires a pointer to class; type found was 'struct WF_SEARCH_WU'.
2
1848
by: Bill Maclennan | last post by:
Hi, Part of my code receives data in a char array, with pairs of characters representing a hex value - e.g. Array = "1234abcd" really represents 0x12, 0x34, 0xab, 0xcd. I need to convert the pairs of characters into ints, is there a nice elegant way to do this? I have currently implemented a switch solution (below), but it seems a bit messy. int convertChar(char tChar){ switch(tChar){ case 'A': case 'a':
41
12461
by: nospam | last post by:
If I have a string say: myvar = "This is a string"; How do I use sprintf to convert the string so it has 4 spaces padded on the left like:
0
10148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
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
7368
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
6643
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
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...
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
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.