LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-01-2013, 08:43 PM   #1
georgewhr
Member
 
Registered: Nov 2012
Location: SF Bay Area
Posts: 47

Rep: Reputation: Disabled
how to append a character on argv[]?


Hello Guys, I m trying to append a character on each argv[].

buffer[256] = "";

for(i = 1; i < argc; i++)
{
strcat(argv[i],";");
strcat(buffer,argv[i]);
}

printf("buffer is %s", buffer);

If I type ./app hello there here, I want to have the buffer which is like hello;there;here

But the code above seems doens't work. Any idea that how can I append a character at the end of each argv?
 
Old 06-01-2013, 10:20 PM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
You can't add to strings that don't have free space allocated. This should work.
Code:
strcat(buffer,argv[i]);
strcat(buffer,";");
 
Old 06-02-2013, 02:03 AM   #3
georgewhr
Member
 
Registered: Nov 2012
Location: SF Bay Area
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by linosaurusroot View Post
You can't add to strings that don't have free space allocated. This should work.
Code:
strcat(buffer,argv[i]);
strcat(buffer,";");
Thanks bro, butI tried that it doesn't work, if I type "./app george there what",I got print out is:
george;
;
what;
 
Old 06-02-2013, 02:19 AM   #4
georgewhr
Member
 
Registered: Nov 2012
Location: SF Bay Area
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by linosaurusroot View Post
You can't add to strings that don't have free space allocated. This should work.
Code:
strcat(buffer,argv[i]);
strcat(buffer,";");
Hey bro, it works now

thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C programming linux copying argv to wchar_t argv babbab Programming 1 08-09-2012 05:32 AM
Writing a file character by character with a bash builtin command (script). stf92 Linux - Newbie 4 06-30-2012 08:41 PM
Bash scripting: parsing a text file character-by-character Completely Clueless Programming 13 08-12-2009 09:07 AM
Help with argv pilot1 Programming 7 08-23-2003 02:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration