C :: Change Elements Of Char String Array

Dec 16, 2013

why does this give me an error when i try to change the elements of the char string array.

code:

int main(void)
{
char *name = "aaa";
// setup the name
name[0] = 'Z';
name[1] = 'e';
name[2] = 'd';
name[3] = '';

return 0;
}

[code]....

View 3 Replies


ADVERTISEMENT

C++ :: Function To Change Char Array String To Lower Case

Feb 17, 2014

This code ran well until i added in the ToLower function which is supposed to convert the char array string to lower case (based off ascii strategy -32). correct this function so it converts string to lower case and doesn't get errors.

#include <iostream>
#include <string>
using namespace std;
const int MAX = 81; //max char is sting is 80
void ToLower(char s[]);
int main(){
string y_n;

[Code]...

View 1 Replies View Related

C++ :: Function That Declares Array Of Char Of A Size Of 350000 Elements

Jun 5, 2014

I'm working on a piece of code written long time ago. Without getting in the details or too much context here, there is a function that declares an array of char of a size of 350,000 elements, in order to fill it (using a pointer) with the list of all running processes on the machine (using "ps -ejf" on a Linux box).

The size of the char array has been changed from 40,000 to 350,000 sometime along the years, probably because of a lack of space required.

What kind on data structure / storage would you use to store the running processes in order to eventually search for a value in it?

View 2 Replies View Related

C++ :: How To Add Array Elements To String Stream

Oct 17, 2013

This is my code:

#include <iostream>
#include <string>
#include <istream>
#include <sstream>
using namespace std;
int main() {
string groups[3] = {};

[Code] ....

It outputs jibberish. I can do what I need to do but I would need to declare more variables and write more cout's, isn't there a way to add these elements to a stringstream or streambuffer? My goal is to write this program and make it as comprehensive as possible but also with very few lines.

View 1 Replies View Related

C :: Convert Elements Of String Array To Integer

Feb 4, 2014

I'm just learning and C. Here is a code snippit from a program that will compile. It's function is to validate credit card numbers. I have an error I can't find though. the last print statement shows the conversion in reverse string (as integers). Here is the code:

int main (void)
{
char cn[17];
char *cardtype;
int n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14, n15;
int s1,s2,s3,s4,s5,s6,s7,s8;
int oddsum;
int sum;
int total;
int validate;
}

[code]....

View 14 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++ :: 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++ :: 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 :: 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 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++ :: 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/C++ :: Testing String Against Array Of Char

Apr 3, 2013

I have a text file with state names, and state abbreviations, thusly:

ALASKA
AK
ARKANSAS
AR
..and so on.

I have to load the abbreviations ONLY from the file into an array of char[ - (already done and tested).

I have to get a 2 char abbreviation as a string,then test it against the state array to make sure it is a valid abbreviation. As it stands, my test is never finding an invalid abbreviation..

Here is where I get the input:

void getState() {
char state[10];
getString("Please enter the state as a 2 char abbreviation:",state,10);
printf("State Entered:%s", state);
validState(state);

[Code] ....

View 14 Replies View Related

C/C++ :: Convert String To A Char Array?

Apr 29, 2015

How do I convert a string of unknown length to a char array? I am reading strings from a file and checking if the string is a Palindrome or not. I think my palindrome function is correct, but do I do something like char [] array = string.length(); ??

#include <iostream>
#include <fstream>
#include <string>
#include <cctype>

[Code].....

View 2 Replies View Related

C/C++ :: Reversing A String / Char Array

Aug 12, 2013

I'm new in the C programming language, so I tried to create a program that reverses a string. This is my code:

/* Reverse string */
#include <stdio.h>
#include <string.h>  
int main() {
  char s[8]="Welcome";  
 
[Code] ....

The output of the program is "@".

View 5 Replies View Related

C++ :: Assign String To Char Array Of Struct

May 6, 2013

#include <iostream>
using namespace std;
struct box{

[Code].....

C++Dev.cpp:23: error: incompatible types in assignment of ‘const char [15]’ to ‘char [40]’

View 2 Replies View Related

C++ :: Using Isalpha With String Converted To Char Array

Jan 26, 2014

I am new to C++ and I have a two player word guessing game working well. However, I would like to be able to validate whether the word entered by player 1 is a completely alphabetic word using isalpha.

The error I am getting right now is as follows:

"error: array must be initialized with a brace-enclosed initializer
char str[100]=hiddenwordtwo;"

/* isalpha portion of code */
#include <stdio.h>
#include <ctype.h>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
using namespace std;

int main () {
char hiddenwordtwo[100];

[Code] .....

View 2 Replies View Related

C# :: Store Each Char Of A String Into Byte-array?

Apr 25, 2014

I am trying to store each char of a string(string a ="1100") into a byteArray ( byte[] byteArray = new byte[4]. its not showing any error but its storing like below:

byteArray[0] = 49
byteArray[1] = 49
byteArray[2] = 48
byteArray[3] = 48

and what i want is

byteArray[0] = 1
byteArray[1] = 1
byteArray[2] = 0
byteArray[3] = 0

I don't know why but its replacing 1 with 49 and 0 with 48.what am I doing wrong or how to do this?

my code is as below

byte[] byteArray = new byte[4];)/>
int binArrayAdd = 0;
string a ="1100";
foreach (char Character in a)
{
byteArray [binArrayAdd] = Convert.ToByte(Character);
binArrayAdd++;
}

View 4 Replies View Related

C/C++ :: Passing String Variable To Char Array?

Mar 30, 2014

I have program where i have to check to see if file exist, if it does not then it needs to be created. SO I have a read file that works fine, if th efile exist it reads whats in it, if it does it says the file does not exist. Now Im trying to creata function that creates the file if it doesnt exist. so in my read function when the person enters the name of the file to be checked for..I pass that name to a variable called name..Hoping that I could then pass it into my create file function if it does not exist..and use that variable to pass the name they entered into the createfile array..called filename.. but I am having trouble because i get error when i try to pass from a string name to char array.. even when I change the varialbe name to char, or char [256] it will not work.. I try to fing a way to convert th string to a char using the strncopy function but still no dice..here the code i have for the createfile funciton

void CreateNew(ofstream & FileNew)//Create file
{
char filename[256];
string name;

[Code].....

How can i do this without having to ask the person to enter the file name twice..

View 12 Replies View Related

C Sharp :: How To Take String Input Into Char Array

Sep 24, 2014

I want to take string input into a char array.

What is the functionality for the above problem.

View 1 Replies View Related

C++ :: Why Cannot Copy String Pointed By Pointer To Array Of Char

Feb 22, 2013

I have this function in a class: and a private declaration: how can I copy the parameter "ProductName" to allowedProductName. I tried all combination and I can't get it to compile.

private:
StatusPanel &statusPanel;
char allowedProductName[MAX_NAME_LENGTH];

[Code].....

View 9 Replies View Related

C++ :: How To Assign Char Array As User Defined String Object

Apr 17, 2014

STRING s1 = “FOOBAR”

Here STRING is a user defined class. how to assign a constant char array "FOOBAR" to string object? Copy constructor need to be same class type as parameter. and overloading assignment operator also need to be same class type. I think 'friend' can let pass another type of object rather than STRING to do operation on overloaded '=' operator. How could it be done if it is possible at all?

View 2 Replies View Related

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

C++ :: Demonstrate String Concatenation - Passing Char Array Into A Function

Oct 10, 2013

I have been assigned the following task and I am having difficulty in getting it to compile. The compiler is stopping at line 27 but I don't no what the error is.

The task is as follows:

Write two functions with the following function prototypes:

int my string len(char str[])
void my string cat(char dest[], char src[], int dest size)

Both functions should take zero-terminated strings as input. The first function should return the length of the string to the calling function. The second function should take a source and a destination string and the total size of the array pointed to by dest. It should then concatenated the source string onto the end of the destination string, if and only if the destination string has the capacity to store both strings. If the destination string does not have the capacity it should not alter either, print and error, and return to the calling function. Demonstrate the use both the above functions by using them in a program in which you initialise two character arrays with two strings, print out their length, print out the combined length, and print out the combined string

And this is my code so far:

/* A program to demonstrate string concatenation */

#include <iostream>
#include <string.h>
using namespace std;
int my_string_len(char str[]){ // function to calculate length of a chracter array
int len = 0;

[Code] ....

View 8 Replies View Related

C++ :: Comparing Char Array To Char Always Returns True

Dec 23, 2014

I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.

this is the entire code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.

View 4 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/C++ :: Why Doesn't String In Vector Change Value

Apr 22, 2014

I am trying to change the value of of time in my vector of structs. The result should output 1430 as the value of shares[1].time though I get something different.

unsigned convTime = 1430;
std::stringstream out;
out << convTime;
shares[1].time = out.str();
std::cout << shares[1].time;

But my shares[1].time stays as its original value and not 1430.

View 1 Replies View Related







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