how to store string in variable


 
Thread Tools Search this Thread
Top Forums Programming how to store string in variable
# 1  
Old 03-14-2012
how to store string in variable

sorry i'm newbies c programer

how to store string to variable with value flexible.

example

int hh=1; ---> value flexible 1,2,3,4,5;
int xx=1; ---> value flexible 1,2,3,4,5;
char test="value=%d and value=%d",hh,xx; --> not working
char test2="value2=%d and value2=%d",hh,xx; --> not working

char complete=test+test2; ----> merge string not working
sprintf("%s",complete);


want output

value=1 and value=1 value2=1 and value2=1


please help me

thank you for advance.
# 2  
Old 03-14-2012
define the test char array
Code:
int hh=1;
int xx=1;
sprintf(test,"value=%d and value=%d",hh,xx);
printf("%s",test);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Store ^M character in variable

Hi, I want to store ^M character in a variable to be later written to a file. Can you please help. TempOut="$_var1 `print '\x0D'` $_var1" ..... .... echo $TempOut >> logfile TempOut="$_var1 `echo -e '\x0D'` $_var1" ..... .... echo $TempOut >> logfile But both ways I am... (2 Replies)
Discussion started by: tostay2003
2 Replies

2. Shell Programming and Scripting

I can't store value in the variable

!#bin/bash clear var= grep @gmail.com email.txt | wc -l echo $var echo $var exit 0 OUTPUT: 1000 _ _ Where _ represent space (no value or nothing) (4 Replies)
Discussion started by: Muhammad Rehan
4 Replies

3. Shell Programming and Scripting

Extract a string from a file and store it in variable

Hi, I've a file ImageSizeDetails.txt with the following contents: Image Name: swncd 01.10.00.04 Created: Wed Jan 9 14:05:48 2013 Image Type: ARM Linux Multi-File Image (gzip compressed) Data Size: 7351011 Bytes = 7178.72 kB = 7.01 MB Load Address: 00008000 Entry Point: ... (6 Replies)
Discussion started by: Parameswaran
6 Replies

4. Shell Programming and Scripting

how to store output to a variable

I need some help: 1) I have a out put from a shell script, the out put looks like this: Attempting privilege escalation using sudo ... List backups for CLTST: Start date Status Ret. Class Label -------------------- ------------ ------------ ... (2 Replies)
Discussion started by: samk
2 Replies

5. UNIX Desktop Questions & Answers

How to store the value of grep in a variable

Hi , I was trying to store the value of a grep command to store in a variable so i can use it somewhere else in my script but i am getting error, i am using bash shell in linux: var= `grep -n "$DATE" testfile.log | head -n 1 | sed -n 's/^\(*\).*/\1/p` echo "$var"I get the error: unexpected... (5 Replies)
Discussion started by: learninguser235
5 Replies

6. Shell Programming and Scripting

Search file for string and store last result to variable

Hi, I'm trying to search a text file for a string: "energy(sigma->0)=". To do so, I executed the grep command, which returned many matches, for example: energy without entropy = -112.16486170 energy(sigma->0) = -112.16520778 energy without entropy = -112.16488936 ... (5 Replies)
Discussion started by: gwr
5 Replies

7. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

8. Shell Programming and Scripting

Help in scripting, store value in variable

Hi all, I have a script in which i need to run a command like "/opt/dell/srvadmin/sbin/omreport about" and output will be something like Version : 6.3.0 Copyright : Copyright (C) xxx Inc. 1995-2010 All rights reserved. Company : xxx Inc. In this i need to save the version... (13 Replies)
Discussion started by: Renjesh
13 Replies

9. UNIX for Dummies Questions & Answers

How to Store command O/P to a variable...

Hi all.. I got a problem.. Its easy to redirect o/p to a file.. But Is it possible to redirect the O/P to a variable? For example: I've a command in my script: string1=cut -d ':' -f2 file.txt When I do: echo $string1 The value is empty... Pls suggest me how to store the value... (7 Replies)
Discussion started by: smartbuddy
7 Replies

10. Shell Programming and Scripting

To store the output in a variable

Hi, I am getting the following error while executing the script. Please can someone throw some light where is the problem. Many thanks. ./check: temp: not found The directory related to SEP instance 4 does not exist. The script is as follows. SEP_APP="/scp/sepx/app... (2 Replies)
Discussion started by: Sudhakar333
2 Replies
Login or Register to Ask a Question