The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
perl: simple question on string append the_learner Shell Programming and Scripting 1 05-14-2007 06:09 PM
Simple C question... Hopefully it's simple Xeed High Level Programming 6 12-15-2006 02:29 PM
concat string mpang_ Shell Programming and Scripting 1 07-25-2006 07:03 AM
Concat dhananjaysk Shell Programming and Scripting 1 03-20-2006 07:42 AM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 01:03 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-23-2007
the_learner the_learner is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 75
simple question on string concat

This is a simple question...

Code:
char *str = NULL;
int  num = 0;
scanf ("%d", &num);
str = ???

I want str to point to the string num.txt

For e.g: If user enters num = 5,

str should point to "5.txt"

How do I do that ?

Thanks
  #2 (permalink)  
Old 08-23-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
char buf[10];

snprintf(buf,sizeof(buf),"%d.txt",num);

str=buf;

Last edited by porter; 08-24-2007 at 01:47 AM..
  #3 (permalink)  
Old 08-24-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,777
Code:
/* try */
snprintf(buf,sizeof(buf),"%d.txt",num);
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0