Regarding extra garbage after string value

2013-08-07  Source: Original Site  Category:C++  Views:0 

Advertisement

First of all, I am a newbie to C++..So please dont get irritated since its a very basic question.
Please find the attached code.
Its like, if I input a string to the console (ex. test), it should print aaaa (Test contains 4 characters). However, its printing some garbage values also along with aaaa.
Please let me know the reason for the same.

Thanks,
cspek

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

bool InitializeChars(char initChar[],int length)
{

try
{
for(int i = 0; i < length; i++)
{
initChar[i] ='a';
}
}
catch(...)
{
cout << "Error initializing array" << endl;
return false;
}

return true;
}

bool printChars(char *str)
{

cout << str << endl;
return true;
}

main()
{
cout << "Please enter a line:\n";
string s;
getline(cin,s);
cout << "You entered " << s << '\n';

int len = s.length();

char * stringChar = new char [len];

bool b = InitializeChars(stringChar, len);

b = printChars(stringChar);

}

Related articles
  • Regarding extra garbage after string value 2013-08-07

    First of all, I am a newbie to C++..So please dont get irritated since its a very basic question. Please find the attached code. Its like, if I input a string to the console (ex. test), it should print aaaa (Test contains 4 characters). However, its

  • Regarding the error - 'incorrect string value ' while migrating data from ingres to MYSQL 5.2 2014-11-10

    Getting the incorrect string value while migrating from ingres to MYSQL 5.2 We have changed the collation and character set on fields of certain tables to UTF8 and utf8_general_ci and it has worked. There is still one table giving the error 'incorrec

  • Oracle datapump QUERY parameter with string values?? - SOLVED 2012-08-03

    All, I am trying to specify a query parameter to the datapump API but cannot seem to get my single/double quotes correct to allow it to work. I can successfully use the QUERY parameter with something like QUERY=table:'"number_column=6"' but NOT with

  • MySQL Replication: [ERROR] Slave: "Incorrect string value" 2012-09-22

    When replication between Master and Slave used Mysql 5.0.33.on Slave machine,I found a error which no is 1633,and information is follow: [[email protected] var]# tail mjcnode02.err 070309 12:26:20 [ERROR] Slave: Error 'Incorrect string value: '\x81\x81\

  • Problem to retrieve input string value 2013-05-02

    I installed php 4.2.3 and apache 1.3.26 on windows 98. It failed to get the input string value from the form. I have a login form which have two input field called login and password. When I tried to retrieve it using $login and $password, not thing

  • MySQL Unable to insert special character from command prompt - incorrect string value 2013-11-13

    From the command line mysql client, I am unable to insert a degrees sign like so: Here's a log of my session: mysql> insert into property (unit) values(0xB0); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> show warnings; +---------+-----

  • Ubuntu Extra garbage when typing in command line 2014-08-14

    I'm currently running an Ubuntu 7.10 (gutsy) server, and I have the following problem when using the local command line. When I enter commands, everything works fine. However, when I go back and edit a command, extra garbage is added at the end. This

  • javascript algorithm to create html url string from sum of string values 2014-09-16

    for anyone who posts long threads... ========================================= i spent an hour writing this long message, and the thread post must have timed out, when i want to submit, i had to relog in and it got deleted cause i couldn't go back to

  • Problem gettin string value from class module 2015-02-22

    Hi, I'm doing a homework dll with multiple class modules but I'm having problems getting string value from a class to a form here's the code this is the class where I send the value from the form Option Explicit Private myBodega As New dllBodega.clsB

  • Ignore single quote from a string value 2015-03-31

    Just wondering on how to ignore single quote in the string value. e.g : myString := 'd' best cuisine'; how to ignore the single quote after the letter d, as it should be a part of the string value. i've tried something like myString := 'd\' best cuis

  • How to get the same query string value? 2012-02-11

    i really need your help to solve my problem.. this is the scenario : first, user choose link "detail" at document table.in that detail,i have a hyperlink "comment". in aspx i wrote this code : <a href="ShowComment.aspx?id_document=<%#Eval("id_d

  • Sphinx How to set a filter with the orginal string value 2012-03-22

    I have two varchar columns that I would like to index, so I used sql_attr_str2ordinal in sphinx.conf. sql_attr_str2ordinal = category_id sql_attr_str2ordinal = merchant_id My question is, is there a way to set a filter with the original string value

  • Oracle how to covert string value to number 2012-03-27

    I want to convert string value to number ex:- select col from t1 where p1 = '232'; the above query will return like bellow value '123,343,534,433'; i have to pass the value in another query where condition like bellow select * from t2 where p2 in(123

  • Need to convert a string value into integer value from a radio field 2012-03-31

    Hopefully this makes sense, but I have been trying to make something work for a while now. I have a form and am collecting all the radio button values that are choosen and have been displayed in an input text field either with the onfocus or onclick

  • Oracle convert zip code string value into decimals 2012-04-27

    Hi I would like to convert zip code into decimal value with out losing leading zeros. Ex: I have zip code called '06095'. When i am trying to converting this string value into decimal value, i am getting 6095. But i am loosing zero before that. Pleas

  • adding numeric value to string value 2012-05-08

    I have a table that contains a string value. This value is actually numeric, eg 001234, but it needs to keep the double 0 in the front. how do I add 1 to the value so that it still keeps the double 0 in the front? eg 001234 + 1 = 001235

  • String value 2012-05-19

    I'm trying to replace a string value with the following condition. As soon as the string hits a period (.) I'm trying to surpress the remaining string value including the firlst period. "LaplanteC.IOD.CDB.1234.HQ.TEST.CA" should now read "LaplanteC"

  • HELP -- assign a dynamically created LinkButton to a string value 2012-06-06

    Please help me. So far nobody was able to help. I am trying to assign a dynamically created LinkButton to a string value. I have a function and there is definitely something wrong with it and I need someone to tell me if it can be done or not. This i

  • Sub: Reading string value from mianframe and converting in to double using 2012-07-02

    i, We are reading the string value from mainframe and converting using PacketDecimal class and getting the double value in java. so when converting from PacketDecimal to Decimal, amount vlaue is getting reduced for some values. But for some values it

  • assign a dynamically created LinkButton to a string value 2012-07-08

    Please help me. So far nobody was able to help. I am trying to assign a dynamically created LinkButton to a string value. I have a function and there is definitely something wrong with it and I need someone to tell me if it can be done or not. This i