LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 02-17-2020, 12:37 AM   #1
justwantin
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Slackware, Slackwarearm
Posts: 878

Rep: Reputation: 120Reputation: 120
C program: append variable in middle of string


I am sure there is an answer to this and I do not know what the search words should be. I have a devices that may change number on reboots /boots I need to reset a command based on a device's number post boot.
Code:
int veml_devno = 1;

in_file = fopen("/sys/bus/iio/devices/iio:deviceveml_devno/in_uvindex_input", "r");
In the example above I am appending the variable to 'device' and prepending it to '/'. Is this possible in C? I've used curly braces in Bash to do this. Having a second thought, should the variable be a char? But then it sill has to be inserted into the command.

Last edited by justwantin; 02-17-2020 at 12:46 AM.
 
Old 02-17-2020, 02:34 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
most probably sprintf is your friend.
 
5 members found this post helpful.
Old 02-17-2020, 03:27 AM   #3
justwantin
Member
 
Registered: Aug 2003
Location: Melbourne, Australia
Distribution: Slackware, Slackwarearm
Posts: 878

Original Poster
Rep: Reputation: 120Reputation: 120
Ta mate, I'll have a go with that tomorrow.
 
Old 02-17-2020, 09:26 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Quote:
Originally Posted by justwantin View Post
Ta mate, I'll have a go with that tomorrow.
Great. If you have further questions about it, please post the code you have showing what input/output results you get versus the intentions.
 
1 members found this post helpful.
  


Reply

Tags
append variable, c program, prepend variable



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
[SOLVED] sed append string in variable to last line of file. SilversleevesX Linux - Newbie 7 11-27-2011 11:13 PM
[SOLVED] copy string a to string b and change string b with toupper() and count the chars beep3r Programming 3 10-22-2010 07:22 PM
[SOLVED] append variable string in a specific line himu3118 Programming 4 06-08-2010 08:49 AM
Append variable string(s) at end of each line schaganti Linux - Newbie 2 10-19-2007 01:31 PM
BASH append to middle of file baks Programming 4 02-28-2007 03:27 AM

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

All times are GMT -5. The time now is 12:41 AM.

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