C/C++ :: Appending Char To String
Dec 1, 2013
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char states [6][10]={"start","InNum","InID","Done","InASG","InCOM"};
char state[] = "start";
[Code] .....
I am trying to take each character from a file and put it in a string and print this string but when i write this code , it doesn't give any output.
View 6 Replies
ADVERTISEMENT
Apr 13, 2013
how to combine a string value with a local buffer containing time and date. I can't seem to get the syntax correct or find an example of this.
So I'll have a result like: The time is: 12:49 04/13/2013. My project will put different values in String mess1 depending on what's happening.
My code
char buf1[20];
String mess1 = "The time is:";
sprintf(buf1, "%02d:%02d %02d/%02d/%4d", hour(), minute(), month(), day(), year());
//mySerial.println(buf1); // operates perfect
mySerial.println(mess1 buf1); // Does not compile - error: expected `)' before 'buf1'
I have also tried a comma between (mess1, buf1), no dice.
View 3 Replies
View Related
Dec 31, 2013
I was trying to append two binary file specially EXE . So I coded this
#include<iostream>
#include<fstream>
using namespace std;
main() {
char ch;
char first[19], last[19];
[Code] ....
This Code Append file successfully but when I Execute the appended Exe, only the first EXE will execute, why and how to fix it so that successively both of exe will execute .
View 5 Replies
View Related
Sep 29, 2014
I'm having a little problem with System::String and terminating the text to end the line in the textbox, I tried adding
to the string in multiple ways (Insert, or just + " ")) but the text is still appended in one single line.
However converting a properly terminated char array to a string and appending it to the textbox works. So, let me explain my code a little more: I have a function which appends text to the textbox (I use it from a different thread thus I needed to use Invoke):
void mainTextboxAppendText(String^ text) {
if (this->mainTextbox->InvokeRequired) {
dMainTextboxAppendText^ d = gcnew dMainTextboxAppendText(this, &mainForm::mainTextboxAppendText);
this->Invoke(d, gcnew array < Object^ > {text});
} else {
this->mainTextbox->AppendText(txt + "
");
}
}
But when I try to call it multiple times with different strings then they do not appear in new lines but they're all in one single line, I've tried doing it like:
txt->Insert(txt->Length, "
");
this->mainTextbox->AppendText(tx);
I've also tried using Environment::NewLine, but it still didn't work, so what I finally came up with was converting the system string to an char array using Marshal and inserting an " " there and then converting it back to an system string, then it was ok .
View 3 Replies
View Related
Sep 18, 2013
A user enters a query and other users reply to it. But it creates a problem here. After adding queries, if I wish to reply to query in between then it adds a redundant entry in file. 1st entry is the original query without reply and 2nd entry is the same query now with a reply added. I want only 1 entry of the query along with replies.Here is the code:
Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include "var.c"
int check_count();
void add_query();
void add_reply();
}
[code]....
View 9 Replies
View Related
Dec 20, 2014
I have the codes for such a problem where, to create a program that counts how many times the second string appears on the first string. Yes it counts if you put 1 letter only, but if you put 2, it is an error. As an example. If the first string is Harry Partear, and the second string is ar, it must count as 3. Here's the code:
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
[Code] ....
View 6 Replies
View Related
Apr 20, 2013
I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.
// Get value from ListBox.
char selectedValue[256];
memset(selectedValue, NULL, 256);
SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue);
// Convert to string.
string val(selectedValue);
[Code] ....
View 3 Replies
View Related
Feb 5, 2013
A string class that finds a char in the string?
View 1 Replies
View Related
Apr 5, 2013
I have this problem that I don't know how to sort out. I have a feeling it's really simple
#include <iostream>
#include <string>
void main () {
char test[10] = "gorilla";
char try = test[1];
cout << try;
}
I get the error:
lab4.cpp:6: error: expected primary-expression before "char"
lab4.cpp:6: error: expected `;' before "char""
View 2 Replies
View Related
Mar 4, 2013
how can I find ASCII value (0..255) of a character char in a string?
I have an array of char:
Code: char myarray[50]; and I need to have ASCII value of character eg myarray[10]. How can I do that?
View 1 Replies
View Related
Oct 19, 2013
I have some code:
char cHomeTeamFaceOffsPercentageWon[100];
memcpy(cHomeTeamFaceOffsPercentageWon,cSqlHomeTeamFaceOffsPercentageWon,100);
After this, for example, cHomeTeamFaceOffsPercentageWon is, "29%".
Then, I use
std::string szwPercentageWon = std::string(cHomeTeamFaceOffsPercentageWon);
szwPercentageWon is then, "2". Shouldn't this convert correctly, to "29%" as well.
Or is there something I'm missing? Maybe the termination character, or something.
View 1 Replies
View Related
Apr 30, 2013
Is there anyway to convert std::string to char*?
Like:
std::string x="hello world";
char* y=x;
View 6 Replies
View Related
Feb 8, 2015
I have had quite a head spinner on trying to transform a string into a char. I've been trying to do this for the project below.
[URL] ....
std::string str = "string";
const char* chr = str.c_str();
cout << *chr << endl;
Above is the code I have tried using and it stores data under *chr, it however only stores one letter rather than the entire word like for example string.
View 2 Replies
View Related
Jul 5, 2013
I have this code working:
char tmp_wku[3];
tmp_wku[0]=0x01;
tmp_wku[1]=0x9D;
tmp_wku[2]=0x62;
char tmp_com[11];
[Code] ....
This sends the buffer to a LIN modem. My question is: can this be done better. If I have a astring of hex numbers like "09 98 88 55 42 FF 00 00 FF BD 89". How could I send this without manually makng a char with hex numbers?
View 1 Replies
View Related
May 7, 2013
Is there a way to replace 3 char's in a string. For example i have a string containing
s = "The school is called 7x8"
I want to replace the "7x8" with "LSU". But the "x" can be any letter or number.
Is there a way to do that ?
View 6 Replies
View Related
Aug 9, 2013
I've to do a function that removes char(input by user) from string , only if it appeared and to reduce spaces.
for instance: string = abcabcd ; and the char= c/
the return string is : ababd
void removeChar(char string2[SIZE], char ch) {
//---NOTE--- its not completely works - there is a problem i.
int read = 0, write = 0;
[Code].....
View 6 Replies
View Related
Jun 7, 2013
I have a question on conversion between char & string. I have cut & pasted the part of the code from my C++ code and my function "decryptPwd" uses C style code with "char" etc.
I need to pass a string (mypwd) somehow to this function after conversion & then compare it to another string (newmypwd).
I tried - "decryptPwd(mypwd.c_str())==newmypwd.c_str()" but it did not work.
..
#include <string>
..
char* decryptPwd(char hash[64]);
main () {
string mypwd;
string newmypwd;
if (decryptPwd(mypwd)==newmypwd)
[Code] ...
View 7 Replies
View Related
Jun 12, 2013
Is there a more simple method to copy Buf into str? Buf is a binary string.
Code:
void function(string & str) {
int iWholeSize = 512;
char * Buf = new char[iWholeSize];
.... operations on Buf
string s(Buf, Buf + iWholeSize);
str = s;
}
View 5 Replies
View Related
Mar 30, 2014
In this program, I have to ask the user for an employee, then the program will check to see if the file for that employee exist, if it doesnt then it will automatically create the file.
ReadNew function reads the file....check to see if it exist
CreateNew function creates a new file.
In my code I have no problem with the first part of reading file.. and my createnew function works in other programs where I am asking for input of file name to create the file name. However in this code I cannot figure how to automatically pass the input filename from the ReadNew function to the CreateNew function. I can't ask the user to enter the name a second time, so I have to pass the input filename into both functions. Here is my code.
Code:
//Create a file, append to it, and read it.
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
using namespace std;
char filename[256];
string n;
string filelist;
void CreateNew(ofstream & FileNew);
[Code]...
View 1 Replies
View Related
Jan 3, 2015
I am trying to save 5 persons names to a struct, and then printing them afterwards, shortly before the program ends. I tried to print the char string out right after it has been copied over, and it showed fine, but when i try to write it out right at the end of the program (its in a separate function) the terminal just prints gibberish.
the function looks like this:
Code:
int printUser(){
printf("Following patients have been recorded in this session:
");
struct database patient1;
struct database patient2;
struct database patient3;
[Code]...
the output looks like this(as you can se in under structest, that it shows the correct string, it also uses printf):
View 7 Replies
View Related
Oct 15, 2013
Currently I have:
Code:
char my_array[4] = { '1', '2', '3', '4' };
how do I convert the above to a string of: "1234"
View 6 Replies
View Related
May 17, 2014
I want do delete all occurrences of a char in a given string, but I really don't see my error in the code. Here is how I did it:
Code:
char *input = "example_string";
int len = strlen(input);
char *new_line[len];
char bad = 'e'; //the one to delete
int i;
int j = 0;
[Code]...
I get segmentation or bus errors.. And I also don#t understand the warning I get. new_line is an array of chars, and I am trying to assign to it a certain char.
View 5 Replies
View Related
Sep 16, 2013
I'm extremely rusty at C but is this the best way to store an input string into a char*?
Code:
int length = 100; //initial size Code: char * name = malloc(length * sizeof(char)); //allocate mem for 100 chars
int count = 0; //to keep track of how many chars have been used
char c; // to store the current char
while((c = getchar()) != '
'){ //keep reading until a newline
if(count >= length)
name = realloc(name, (length += 10) * sizeof(char)); //add room for 10 more chars
name[count++] = c
}
Is this a good way and what could be better?
View 2 Replies
View Related
Mar 8, 2013
.I have this string that I need to convert into a 2d char array like this:
String str= "A,E,B,I,M,Y#N,R,C,A,T,S";
I know how to use delimiter and split string and I know how to convert but only from string to char[].I need something like this:
Input: String str= "A,E,B,I,M,Y#N,R,C,A,T,S";
Output: [A] [E] [B] [I] [M] [Y][N] [R] [C] [A] [T] [S]
View 6 Replies
View Related
May 27, 2014
So I have an array of char called s.This array has many words inside, each one separated by ''.The words are sorted by length (from bigger to smaller).I have have a char matrix with random things inside (it was not initialized) caled mat.I want to copy the first word from the array s to the matrix mat.
Code:
int nlin, ncol; /*number of lines and collumns.*/
int c,l,a,q;
char mat [1000][1000];
char s[1000];
}
[code]....
I can't see where this is wrong, but, when i test it, it clearly is not right. for example, if the input is 3 lines and 3 columns for the matrix and the word is crate, the output is :
cra
t
e
but it should be:
cra
t
e
View 11 Replies
View Related
Apr 12, 2014
I want to make a program that receives the number of lines and collumns of a matrix, a matrix of char, the number of pairs of coordinates and the coordinates. the program has to return the char (or chars) that are on those coordinates on the matrix.
Example:
receives
2 3 ABC DEF 2 1 1 1 2
returns
AB
this is how i tried to solve this problem:
Code:
#include
#define MAX 1000
int main() {
int nlin, ncol;
char mat[MAX][MAX];
int x[MAX], y[MAX];
int ncoords;
int l, c, n;
/* receiving variables and storing matrix.*/
[Code] .....
For some reason that i can't seem to find, this solution is not right.
View 6 Replies
View Related