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

combine user input variable with normal variable

109 100+
Hi I want to combine these variables:

char computera[10]; //this variable contains input from the user
char path[]= "\\\\";
char location[] = "\\C$\\Windows\\System32\\chat.txt";

The order I want them in is:

path[] + computera[10] + location[]

I have tried this to get the first two variables joined together:

strcat(path,computera);

However, when I tried to print this to check that it had worked, some weird symbols came up.

Any ideas?
Jun 20 '07 #1
2 2073
mac11
256 100+
Hi I want to combine these variables:

char computera[10]; //this variable contains input from the user
char path[]= "\\\\";
char location[] = "\\C$\\Windows\\System32\\chat.txt";

The order I want them in is:

path[] + computera[10] + location[]

I have tried this to get the first two variables joined together:

strcat(path,computera);

However, when I tried to print this to check that it had worked, some weird symbols came up.

Any ideas?
you have to create a buffer large enough to hold everything and then strcat/strcpy/whatever into that
Expand|Select|Wrap|Line Numbers
  1. char buff[1024] = {0}; //1024 should be big enough!
  2. ...
  3. ...
  4. strcpy( buff, path );
  5. strcat( buff, computera );
  6. strcat( buff, location )
  7.  
Jun 20 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
This is for C:
char buff[1024] = {0}; //1024 should be big enough!
...
...
strcpy( buff, path );
strcat( buff, computera );
strcat( buff, location )
This is how it's done in C++:
Expand|Select|Wrap|Line Numbers
  1. string computera; //this variable contains input from the user
  2. string path("\\\\");
  3. stirng location("\\C$\\Windows\\System32\\chat.txt");
  4.  
  5. //The order I want them in is:
  6.  
  7. path= path + computera + location;
  8.  
  9. //and you are done.
  10.  
Jun 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Dave | last post by:
Hello, I'm a somewhat PHP newbie, so please bear with me. Here is what I am trying to do: $foobar = "blah blah"; $a = "foo"; $b = "bar"; $fooboo = "$a" . "$b"; echo $fooboo
9
by: CW | last post by:
I wrote an HTML based chat application. The front end is built entirely on HTML + javascript. Essentially, I have a hidden frame that's refreshed frequently and any new messages are displayed in...
3
by: Nick | last post by:
I am working a new application...well actually a series of applications for my company. They want internal users to be able to go to a site and everything regarding security is transparent,...
8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
4
by: simon | last post by:
hello. relatively new to vb.net, i'm using VS 2003 and .net 2.0 i have a web app that i'm i have a user control that displays a simple 1 row table as the header of the page. the user control...
4
by: ghjk | last post by:
In my php application user should enter date and time separately. But i want to combine them to compare with database value. How can i do that? user input Date:2008-03-25 User input time:11:30 Eg;...
30
by: Yorian | last post by:
Hey, Although I've been using classes and object for quite a while now I've never actually programmed proper OO code yet. It ofcourse depends on what you call proper OO code. I have been...
3
by: fjm | last post by:
I have one jquery function that submits data via a datastring to my server. This works great. On success, I currently have a little alert box that lets the user know that the data was stored. I...
1
by: Alexio | last post by:
I have two similar function that need to be combined. Individually they both work however combined one over rides the other. The code is attached below and an attachment is included for data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.