C++ :: String Class That Finds A Char In String?

Feb 5, 2013

A string class that finds a char in the string?

View 1 Replies


ADVERTISEMENT

C/C++ :: Implement String Class And Modify Specific Char

May 4, 2014

I tried to implement a string class and i want to modify a specific char in my string . I did operator over load but this code crash in this line

name [2] = 'k' ;

Why ?!!!!!!!!!!!!!

this is my code

# include <iostream>
using namespace std;
#include <assert.h>
class String {
public :
char *content ;
int size ;

[Code] ....

View 11 Replies View Related

C++ :: Count String In A String Using Datatype Char

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

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 :: Function Which Finds Largest Contiguous Values Of Char In 2D Array

Nov 5, 2013

I am required to write a program which, when given an nxn 2D array of char, and the specified coordinates of a specific point in that array, returns thelargest number of horizontal, vertical or diagonal contiguous (side-by-side) sequence of points of that same char value that intersects with the given point.

The way I took on this problem was to:

1) First find out the number of points with the same char value up, down, right, left, north-east, north-west, south-east, and south-west of the given point.

2)Add up+down+1(the one is for the point itself), north-west+south-east+1, etc...

3) Finally I compared the four values (updown, rightleft, NESW, NWSE) and returned the largest one.

Well, that's how the program is supposed to work in theory but as you can probably guess it doesn't work. In addition to telling me what I'm doing wrong, is there a simpler way to do what I am trying to accomplish?

Here's the code:

Code:

int findLongest(char **board, int n, int row, int col)
{
char current;
int rightleft, updown, NESW, NWSE;
int r, c, c1=0, c2=0, c3=0, c4=0, c5=0, c6=0, c7=0, c8=0, d;
int t1=1, t2=1, t3=1, t4=1, t5=1, t6=1, t7=1, t8=1;
current=board[row][col];
//check Above: col remains the same
for(r=row-1;r>=0||t1!=0;r--)
//with the condition r>=0 I made sure not to accidentally check values outside of the array

[Code]...

View 1 Replies View Related

C++ :: Getting A Char From A String

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

C :: How To Get ASCII Value Of A Char In A String

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

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++ :: Convert String To Char

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

C++ :: How To Transform A String Into A Char

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

C++ :: Convert String Of Hex To Char

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

C++ :: Replace Char In String

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

C++ :: Remove Char From String?

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

C++ :: Conversion Between Char And String

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

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 View Related

C++ :: Binary Char Pointer Into String

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

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

C :: Printing A Char String From A Struct

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

C :: Convert Char Array To String

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

C :: How To Delete All Occurrences Of A Char In A String

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

C :: Best Way To Store Input String Into Char

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

C :: How To Convert A String Into 2D Char Array

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

C :: Printing A String On A Char Matrix

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

C :: Searching A String On Char Matrix

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

C++ :: Assign Value Of Pow (2,800) To Char Array Or String

Jan 31, 2015

Assign value of pow(2,800) to char array or string ....

View 1 Replies View Related

C++ :: String To Const Char Error

Jan 15, 2013

I'm currently finishing up an assignment that was half written by my professor. Below in the testGrades section of code there are two errors both are the same message.

Error: no matching function for call to Grades:: Grades(const char [15])

Test Grades

//Purpose: Test program for the class Grades
// Create stu1 Grades object
// Add 5 grades to stu1 - only 3 can be stored in stu1 - other 2 discarded
// Create stu2 Grades object
// Add only 2 grades

#include <iostream>
#include <string>
#include <iomanip>
#include "Grades.h"

using namespace std;

[Code] .....

View 5 Replies View Related







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