string-concatenation

concatenation of character arrays in c

喜夏-厌秋 提交于 2019-12-14 03:34:07
问题 I am trying to concatenate 2 character arrays but when I try it does not work and my o/p console hangs and does not print anything. char *str[2]; str[0] = "Hello "; str[1] = "World"; strcat(str[0],str[1]); printf("%s\n",str[0]); I even tried the below code which fails as well char *str1 = "Hello "; char *str2 = "World"; strcat(str1,str2); printf("%s\n",str1); Can someone explain this? TIA. 回答1: char *str1 = "Hello "; char *str2 = "World"; strcat(str1,str2); printf("%s\n",str1); Here you have

Appending string to input file name in c

强颜欢笑 提交于 2019-12-13 17:35:06
问题 I need to write a program using system calls to read a file, reverse the string and print it out to an output file. If the input file is test.txt , output should be written to file reverse_test.txt . Please let me know how I can append the string reverse_ to the name of the output file where I would be writing the results. I tried the code below but it gives error. strcat("reverse_",argv[1]); I have written the rest of the code and it works fine but unable to solve this part. 回答1: The strcat(

Bad access to memory using strcat

♀尐吖头ヾ 提交于 2019-12-13 17:05:42
问题 I'm using linux. I have a function called like: PlayBackgroundIntroMusic((char *)"IntroMusic"); The functions is: void SoundManager:: PlayBackgroundIntroMusic( char * musicFile) { // Concatenate extension for each platform strcat (musicFile,audioExtension); CCLOG("musicFile: %c" musicFile); SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::fullPathFromRelativePath(musicFile)).c_str(), false); } But i having a bad access to memory on line: strcat (musicFile

php: output[] w/ join vs $output .=

拜拜、爱过 提交于 2019-12-13 13:48:29
问题 I'm modifying some code in which the original author built a web page by using an array thusly: $output[]=$stuff_from_database; $output[]='more stuff'; // etc echo join('',$output); Can anyone think of a reason why this would be preferable (or vice versa) to: $output =$stuff_from_database; $output .='more stuff'; // etc echo $output; 回答1: It was probably written by someone who comes from a language where strings are immutable and thus concatenation is expensive. PHP is not one of them as the

Concatenate PHP function output to a string like variables

被刻印的时光 ゝ 提交于 2019-12-13 08:35:43
问题 For variable $x we can concatenate it to a string in many ways, one of them is like the following: $x = "Hello"; echo "I say {$x} to all of you."; // The output should be: I say Hello to all of you. However, If I tried to do something like this with a function, it will fail: $x = "Hello"; echo "I say {strtolower($x)} to all of you."; // The output should be: I say {strtolower(Hello)} to all of you. If there is a synonym way just like used for the variable, I will be appreciated to know it. In

Concatenating an int to a string or converting in C

那年仲夏 提交于 2019-12-13 05:28:21
问题 Im looking for a 6 digit random number on the end of foo-, I have been trying for a few hours now with no success. only error messages note: expected 'char *' but argument is of type 'int' Ive tried to convert the int to char but it just doesn't like it, My code is below, #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> char* concat(char *s1, char *s2) { char *result = malloc(strlen(s1)+strlen(s2)+1);//+1 for the zero-terminator //in real code you would check for

loop through file saving to variable

戏子无情 提交于 2019-12-13 03:38:19
问题 I now have the following bat file working (which allows one to add text to the end of each line of a file) -- please see also: bat file: Use of if, for and a variable all together @echo off setLocal EnableDelayedExpansion IF EXIST "%FileToModify1%" ( for /f "tokens=* delims= " %%a in (%FileToModify1%) do ( echo %%a Note: certain conditions apply >> "%SaveFile1%" ) ) However, I would like to save each line to a variable (including the new line symbol(s)) and then echo the variable to a file at

Concatenate auto generated strings in java with a space seperator in between

青春壹個敷衍的年華 提交于 2019-12-12 15:19:10
问题 I have a string array variable which values changes continuously. Random arrays are generated from it. This is what i have: String trans = Utility.GetColumnValue(testdata[k], "suggest_text_2"); The trans value changes continuously. How can i concatenate it with the previous values? How can i print every value of trans as it changes continuously? Do i need to use any buffer? 回答1: If you need the intermediate results, you will probably need something like this: String yourOldString; String

Appending BSTR in a LPCSTR

坚强是说给别人听的谎言 提交于 2019-12-12 12:27:03
问题 I have a class function which is receving a BSTR. In my class I have a member variable which is LPCSTR. Now I need to append BSTR ins LPCSTR. How I can do that. Here is my function. void MyClass::MyFunction(BSTR text) { LPCSTR name = "Name: "; m_classMember = name + text; // m_classMember is LPCSTR. } in my m_classMember I want that after this function value should be "Name: text_received_in_function". How i can do that. 回答1: Use the Microsoft specific _bstr_t class, which handles the ANSI

How to row-wise concatenate several columns containing strings?

戏子无情 提交于 2019-12-12 11:22:54
问题 I have a specific series of datasets which come in the following general form: import pandas as pd import random df = pd.DataFrame({'n': random.sample(xrange(1000), 3), 't0':['a', 'b', 'c'], 't1':['d','e','f'], 't2':['g','h','i'], 't3':['i','j', 'k']}) The number of tn columns ( t0, t1, t2 ... tn ) varies depending on the dataset , but is always <30. My aim is to merge content of the tn columns for each row so that I achieve this result (note that for readability I need to keep the whitespace