C++ :: Compare Element Of Char Array And String With Single Character

Dec 3, 2014

how can i compare an element of the char array and string with single chsracter also how to compare char array to cpp string

View 3 Replies


ADVERTISEMENT

C :: Copy Every Single Character From One Char Into Another

Jun 5, 2013

I have some problems with copying a single character from one char into another. How do I do that? Here is the function I am using

Code:

void
text_col (char line[]) {
char line1[1];
int l, ii;
l = strlen(line);

[Code] ....

I am trying to copy in a loop every single character from char line into char line1. That is not working.

View 8 Replies View Related

C++ :: Concatenate Two Char Arrays Into Single Char Array?

Sep 29, 2014

I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.

/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit

[Code]....

View 2 Replies View Related

C :: Assignment Of Element Of 2D Character Array To 1D Character Array

Jul 4, 2014

Can we do this :

Code:
char strings[][100]={"ABC","EFG","IJK","LKM"};
char temp[100];
temp=strings[1];

View 3 Replies View Related

C++ :: Unable To Compare A String With A Char Pointer

Jan 28, 2013

Ok, I'm having a few problems with strings, mostly string functions saying they're not able to compare a string with a char pointer.

int main()
{
int counter = 0;
int x, y, z;

[Code].....

My goal is to take in a command and store it in a string. Different commands have different amounts of information I need. One command is "new flight <flightnumber> <seats available>". First, I try to understand which command is being asked, using the first character to decide. Once I can assume which command is being attempted, I try to separate the string into smaller strings (words) using strtok. I then compare the words that should be constant (new and flight), to make sure the command is syntactically correct (which I use strcmp for). Then I'll go on to create a new flight, which is a class that takes in a char * and integer (which is why I need to convert a char * to integer).

View 2 Replies View Related

C :: Unable To Display Element Of Char String?

Mar 2, 2013

Why I cannot do this to display each element of my char string? What is the proper way?

Code:

char str[SIZE];
int i;
for(i=0; i<SIZE; i++)
{
printf("%s", str[i]);
}

View 4 Replies View Related

C++ :: Reading Two Words Into Single Char Array From Text File

Sep 15, 2014

I am trying to read in player names (ex: first last) from a text file into the people[].name data struct. I can successfully read in my card file, but I cannot get this to work. I get a seg fault. I believe this is because nothing is actually being read in for my while loops. I can't use std::strings so these must be c-style strings aka char arrays.

// deck of cards
// below are initializations
#include <iostream>
#include <fstream>
#include <ctime>
#include <stdlib.h>
#include <string>

using namespace std;
//globals
const int maxCards = 52;

[Code] .....

View 1 Replies View Related

C++ :: Debugging Code (Displaying Char String Per Character)

Jul 16, 2014

I've tried a bunch of alternative methods to prevent an assertion error. "not understanding" the bug and why I'm getting it are relevant here, not proper, (or more appropriate), coding methods. I would write it in another way to prevent the error, I simply want to understand what is happening during run-time that causes the situation.What is the bug?

---------------------------------------
[assertion error]
[expression _block_type_is_valid(phead->nBlockUse)]
--------------------------------

Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Enter your name : ";
string Name;

[code]...

View 1 Replies View Related

C++ :: Compare Single Value With A Value From Linked Lists

May 2, 2013

I'm trying to compare a single value with a value from my Linked list and if they are same, I want to add the value from the list to new list. In other words I want to create a new List with values with the first one. Here is the code that I made, but it's not working.

This is the code with which I search in the first list for a node with a value. In the main() function I have A.find_city(), so it can start from the start_pointer from the first list:

void List::find_city() {
List *temp1;
int b = 0;
char city[20];
cout << "Enter city: ";
cin >> city;
temp1 = start_ptr;

[Code] ....

This is the code with which I add a node to the new list:

void List::in(List *temp1) {
List *temp2;
if(start_ptr == NULL)
start_ptr = temp1;

[Code] ....

View 9 Replies View Related

C :: Set Variable Of Type Char Equal To Element In Array Of Characters

Mar 3, 2014

I am trying to set a variable of type char equal to an element in an array of characters. For example:

char data[4] = "x+1";
char element;
element = data[2];

This seems like a logical progression from number arrays, but when I print both element and data[2], I get data[2] as expected, but element gives a different character every time (I assume a garbage value).

View 5 Replies View Related

C :: Setting Character In Malloc Char Array

Oct 16, 2013

I am attempting to change a character in a character array.In the code below, there are three attempts to do this. Only the first one will succeed. The last two both segfaults. If I understand correctly, str_one is declared in the heap, and could therefore be manipulated; and in contrast, str_two is declared in the stack and is therefore immutable, thus the segfault, when update it is attempted. However, I understand that using malloc, one is able to assign a pointer and allocate space in heap memory. Thus, I should be able to manipulate the assigned variable str_three. Doing so, however, results in a segfault.

Code:

#include <stdio.h>
#include <stdlib.h>

int main (int argc, char const* argv[])
{
char str_one[4092] = "This is string number one";
char * str_two = "This is string number two";

[Code]...

View 2 Replies View Related

C :: Assigning String To Array And Compare It?

Mar 20, 2013

I have this code :

#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

[Code] ...

And this error occued with me I don't know why ???

myHeader.h:42:19: error: expected ")" before string constant

This code is compiled from file called myHeader.h ...

View 2 Replies View Related

C++ :: How To Convert A Single Character Into ASCII

Jan 26, 2014

I am making a text encrypter and I have to convert text into ASCII codes. I know how to convert a single character into ASCII -

#include <iostream>
using namespace std;
int main() {
cout<<"Text to ASCII converter"<<endl<<"Enter text to convert into ASCII - ";
char text; //defining input type, which is single character

[Code] ....

Try it here - URL.....Is there any way to run a similar program, which converts a string with spaces into ASCII code?

View 1 Replies View Related

C++ :: Inserting New Element Into String Array?

Nov 19, 2013

I have the structure defined in the code below and need to insert a new string into the middle of the string array. I know there is a way to insert a new element with a vector. How to do this. I have tried several variations similar to uniqueList.word.insert(400,"disisdabomb"); but with no luck.

const int maxWordCount=1500;
struct wordCountList
{
string word[maxWordCount];
int count[maxWordCount];
};
wordCountList uniqueList;

View 2 Replies View Related

C++ :: Compare A String To Certain String In Array?

Feb 25, 2015

i'm trying to compare a string to a certain string in an array, my code is as follows:

#include <iostream>
using namespace std;
int tu;
int nu=0;

[Code].....

View 5 Replies View Related

C++ :: Convert Element Of Int Type Of Array To Char Type?

Dec 21, 2013

how to convert an element of int type of an array to char type?

View 2 Replies View Related

C++ :: Character Array To Wide String?

Nov 19, 2013

I am still working on my project which will be reading some old data from some old DOS files. The data stored there is naturally, char*. Once I read in my character array, how do I assign this to a wstring since my application is UNICODE?

Here is my current solution:

wchar_t* Class::Function(char *pName) {
//I verify the pointer and such first, then do the below
this->_Name.assign(pName, (pName + strlen(pName));
return this->_Name.c_str();
}

Am I on the right track here?

View 9 Replies View Related

C++ :: Extract And Check First Character Of String Array Is Alphabet

Oct 3, 2013

How i could go about extracting and checking if the very first character in my string array is an alphabet

View 2 Replies View Related

C++ :: Char Array To String - String Becomes Garbage

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

C++ :: Can't Compare Char Strings

Jun 13, 2013

I have two char* that have the same data in (hypothetically).

std::vector<char*> Buff;
Buff = Split(Line, '.');
char* A = "data", B;
B = Buff.at(0)

Where Split is a function that I made to split a string (Line in this case) into a char* vector, this string contains a line from a file. Line is char* too. The weird problem is when Buff data stored in its 0 position is given to B... because B is equal to A (hypothetically) but when this is compared to do certain functions they doesn't match!

Here an example:

std::vector<char*> Buff;
Buff = Split(Line, '.');
char* A = "map", B;
B = Buff.at(0) // Buff.at(0) should be "map" and is apparently "map"

[Code].....

NOTE: I didn't use switch to compare Cmd because I want it separately for easier debugging.

Is there something wrong with my codes?? or what happened here with those hex values before the string in my variables?

View 6 Replies View Related

C++ :: How To Compare Char Pointer With A Range

Sep 19, 2013

I understand you can do

char* charpointer[2];
charpointer = "12";
if (charpointer[0] == '1'){
}

but how can we test for a range? 0-1? so I can compare it to '12'

I wouldn't want to do charpointer[0] == '1' && charpointer[1] == '2' though.

View 1 Replies View Related

C++ :: Compare 2 Dates From Strings / Char Or Int

Mar 16, 2014

i have been trying to compare a date format from SYSTEMTIME and a date from a text file(string).But its not working. I tried to change both to string(using osstringstream),char* and int(using sscanf) to do the comparison but with no luck. its pretty simple all i want to do is get the current system date and compare it with the date from the text file. Below is my code:

char szcurrentDate[MAX_PATH] = "";
char szdate_time[MAX_PATH];
SYSTEMTIME st;
GetLocalTime (&st);
GetDateFormat(LOCALE_USER_DEFAULT,NULL,&st,"yyyy-M-d ",szcurrentDate,MAX_PATH); //current system date
//std::ostringstream mm;

[code].....

note : i tried displaying just szcurrentDate and szdate_time they show the date exactly the same. in string,char* or int formats.

View 2 Replies View Related

C++ :: Char Array To String

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

C++ :: Periodic Table - Char Element?

Mar 11, 2013

Here is the code

#include <iostream>
using namespace std;
int main () {
char element;
cout << " Please enter a symbol. " << endl;

[Code] ....

let's say someone puts in h and Hydrogen comes up, and when someone puts in he, hydrogen also comes up, what am i doing wrong.

View 3 Replies View Related

C/C++ :: Ordering Element (char) In A Struct

Dec 9, 2014

what is the function of ordering element(char)in a struct

View 1 Replies View Related

C++ :: Converting String To Char Array

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







Copyrights 2005-15 www.BigResource.com, All rights reserved