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

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 4584
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.googlegr oups.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::size_type pos(s.find_first_not_of(" "));

if(pos != std::string::npos)
{
s.erase(0, pos);
s += '\0';
std::copy(s.begin(), 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
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...
11
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...
0
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
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
by: MX | last post by:
Welcome! I have something like that: ref class DCAM { ... private: char str; ...
4
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'...
5
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'....
2
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...
41
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:
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.