C++ :: Difficulty Appending Local Buffer Value With String?

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


ADVERTISEMENT

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

Visual C++ :: Retrieving Size Of Each String In Order To Produce A New Buffer For Concatenated String

Feb 25, 2013

What is the efficiency of the two assignments (line 1 and 2), i.e. (function calls, number of copies made, etc), also the Big O notation. I know there are function calls for retrieving the size of each string in order to produce a new buffer for the concatenated string...any difference between line 1 and 2 in terms of efficiency?

String s("Hello");
String t("There");
1. s = s + t;
2. s += t;

View 3 Replies View Related

Visual C++ :: Reverse String Sequence In String Buffer

Apr 27, 2013

I made a simple little program that takes text from the clipboard, and spits out all the lines I've copied one at a time (so my program can analyze it).

everything works perfectly, except, it spits it own in the wrong order, I want it to spit out from bottom to top. but currently it spits out the data from top to bottom. here is my code :

Code:
#include <iostream>
#include <Windows.h>
#include <string>
#include <sstream>
using namespace std;
int main() {
HANDLE clip; // assigns the var. clip to hold a handle ID.

[Code] .....

I want this loop to run backwards! Like it say's what I want to work backwards. Where as I know how to flip a while loop like this: while(x < 5), how to flip a loop like the one I'm using. how I can do this?

View 8 Replies View Related

C++ :: Text For Score And Difficulty Doesn't Seem To Work

Sep 28, 2013

my text for the score and difficulty doesn't seem to work. They are both appearing twice and not updating. The score text worked fine until I inserted the difficulty text and I can't seem to find the problem. URL.....

#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <SFML/Graphics.hpp>
int main()
{
sf::ContextSettings settings;
//settings.antialiasingLevel = 8;

[code]....

View 2 Replies View Related

C++ :: Reading Int Choice In With A String Buffer Instead Of Cin?

Sep 25, 2013

How do you read an int choice in with a string buffer instead of cin?

View 2 Replies View Related

C++ :: Stream Buffer To Base64 String

Oct 2, 2013

I have problem with this code:

#include <windows.h>
#include <stdio.h>
#include <gdiplus.h>
#include "ScreenCap.h"
#include <wchar.h>
#include "base64.h"
#include <sstream>

using namespace Gdiplus;
int GetEncoderClsid(WCHAR *format, CLSID *pClsid) {

[Code] ....

This function return me a long series of Y ended with other chars but not the base64 string.

I think the problem is std::string encodedstring = base64_encode(buffer, dwBufferSize); but I can't figure out the problem.

The base64 function is: [URL] ....

View 2 Replies View Related

C :: String Declaration As Global / Main Local Variable

Nov 14, 2013

When a declare a string e.g.

Code:
char str[30]; as a global variable, the srting is initialized to NULL.

But if I declare char str1[30] INSIDE main(), then the string has garbage inside.... Why this happens??

E.g. the following code snippet...

Code:
#include <stdio.h>
char str[50];
int main(){
char str1[50];

[Code] ....

View 4 Replies View Related

C++ :: Appending Two Binary File Specially EXE

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

C/C++ :: Multiline Textbox And Appending A New Line

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

C :: Appending Content In Middle Of A Text File

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

C++ :: Stopping Threads Without Using Local Var?

Aug 31, 2014

Here's my code,

#include <iostream>
#include <unistd.h>
#include <thread>
using namespace std;
void Blink();

[Code] .....

The problem is i don't want to use local vars , is ther anyway do end the loop safely(removing all the vars used in function and etc) without using a local var ?

View 3 Replies View Related

C++ :: Returning Local Pointer

Apr 24, 2013

I hear all the time about the rule of not returning a local pointer, but I'm not exactly sure what that insinuates. Would this example be classified as violating that rule?

class Foo {
public:
Bar* ReturnBar() {
Bar* temp = &bars.at(0);
return temp;
}

private:
vector<Bar> bars;
};

View 3 Replies View Related

C# :: Unassigned Use Of Local Variables

Nov 20, 2014

//Declare Variables
String lstNme, frstNme, finalGrade;
Double pointsEarned, percentage;
//Get First Name, Last Name and Score

[Code]....

I am getting the error popping up on the line 58 under the console.writeline...+finalGrade "Error1Use of unassigned local variable 'FinalGrade' The thing i am not understanding is that it is declared

View 11 Replies View Related

C/C++ :: Function With Local Variable

Jul 28, 2014

#include<iostream>
#include<stdlib.h>
using namespace std;
int Name(),Minimum(),Maximum();
int main() {
int name=Name(),minimum= Minimum(),maximum= Maximum();

[Code] ...

There are error to let user to key in minimum and maximum values, i would like to know whats the problem?

View 1 Replies View Related

C++ :: Relation Between Local Position And Distance

Feb 21, 2014

i have two point P1 and P2 where i want to move P1 and P2 with keeping the distance and the position of the P2 relative to P1 i thought that when i keep the distance between the two point that involve keep in the same time the local position of P2 but when tested it does not work initial position of P1=(10.0f, 00.0f, 00.0f) initila position of P2 relative to p1 =(50,10,-8) we can get the global position of p2 ----- final position of P1 =(50,10,-8) final position of P2 in the world space =(40.31,8.06,-6.45) then we calculate the distance before and after we found that there are equal but when we calculate the position of p2 relative to p1 after and before we found that there are not equal.

how i can keep the local position and distance ?

View 14 Replies View Related

C++ :: Local Function Definitions Are Illegal

Apr 28, 2014

I was trying to make this program using function and everything seemed to be going great....until I compiled. This is just a project I want to work on myself. It's going to be more than what it is now.

I received next errors:

Compiling...
700Dlg.cpp
E:CPP700700Dlg.cpp(65) : error C2601: 'KeyEvent' : local function definitions are illegal
E:CPP700700Dlg.cpp(106) : error C2601: 'MsgLoop' : local function definitions are illegal
E:CPP700700Dlg.cpp(115) : error C2601: 'KeyLogger' : local function definitions are illegal
E:CPP700700Dlg.cpp(142) : error C2601: 'main' : local function definitions are illegal
Error executing cl.exe.

[Code] .....

I need load keylogger code by MFC Dialog. How I can do it ?

View 7 Replies View Related

C :: Returning A Pointer To Local Variable

Aug 18, 2014

Should i never return a pointer to a local variable. i have seen the following code in the standard text book.

Code:

struct node *add_to_list(struct node *list, int n)
{
struct node *new_node;
new_node = malloc(sizeof(struct node));
// some code here
return new_node;
}

new_node is a local pointer then why is he returning the new_node? Is it wrong or am i failing to understand something?

View 2 Replies View Related

C++ :: Initializing Local One Dimension Array?

Jul 31, 2013

Want to initialize a local one dimensional array. How can I do the same without a loop?

Found from some links that
int iArrayValue[25]={0};
will initialize all the elements to ZERO. Is it?
If yes then can we write below code to initialize the elements to a non-ZERO value?

int iArrayValue[25]={4};

Do we have some other way to initialize an array to a non-ZERO value? Memset can initialize the element to ZERO.

View 7 Replies View Related

C++ :: Temp Or Local Variable Warning

Feb 28, 2014

Here is my overloaded operator :

const double & Waz::operator()(int i,int j) const {
return ((WazImpl const)(*p))(i,j);
}

Where in Waz class I have : WazImpl* p; and in the class WazImpl I have an operator () const

The warning is : Warning C4172 returning address of local variable or temporary

As far as I understand I'm returning a temp variable which is destroyed somewhere else what can I do to fix it?

View 2 Replies View Related

C++ :: Returning Address Of A Local Variable?

Jul 9, 2014

I know that this code is wrong because it returns the address of local variable which no longer exist after function:

int *f1()
{
int x = 2;
return &x;
}

However, why this one does not show problem and runs fine, here the pointer p is also a local variable:

int *f2()
{
int x = 2;
int *p;
p = &x;
return p;
}

View 6 Replies View Related

C# :: Unassigned Local Variable Error?

Jan 27, 2015

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Furniture {
class Program {
static void Main(string[] args)

[Code] ....

I tried changing the type of variable to char but i still get the same result. i also tried using a switch statement which was my first choice but i had the same issue.

View 2 Replies View Related

C/C++ :: Uninitialized Local Variable Errors

Sep 7, 2014

I keep getting the "Uninitialized Local Variable" error. But for my code it's says it's the variable 'pay' in my Manager Function. This is the only error that is popping up.

I've tried setting pay to 0 but when I do, I get a bunch of external errors. I've also tried assigning pay to WeeklySalary like this:

double pay = WeeklySalary;

//Calculating pay for a company

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

//Function prototypes
double managerFunction();
double hourlyWorkerFunction();
double commissionWorkerFunction();

[Code] .....

View 10 Replies View Related

C# :: Unassigned Local Variable In Pay Calculator

Nov 15, 2014

{
//Declare Variables
decimal hrsWrkd, otPay, grossPay, taxRate=0, taxAmount, netPay,basePay, wage;
string maritalStatus;
const decimal WORKWEEK = 40;
const decimal OTRATE = 1.5m;
const double m = 0.15;

[Code] ....

The error message I am getting is Use of unassigned local variable 'otPay' . I see its been declared and been used in the code so the error is confusing, also when i run the program i noticed that it doesn't take out the taxes.

View 4 Replies View Related

C# :: How To Get Rid Of New Line In Buffer

Oct 29, 2014

I have an int array of size 5 and I have my program to accept 5 integers between 10 and 100 inclusively. I should be able to type integers over and over again until I get 5 that are in the range, 10 <= x <= 100. Now when I get 5 that fall in that range the program should continue but instead it wants a 6th number before continuing. I'm suspecting the program is hanging on to a new line character. Anyway to ignore the new lines? Couldn't find anything for C# without clearing the screen.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DupElim {
//dup elimination

[code]....

View 5 Replies View Related

C++ :: Local Function Definitions Are Illegal Error

Mar 6, 2015

Code:

#include <iostream.h>
void showMenu();
void showFees (double, int);

void main()

[Code] .....

View 2 Replies View Related







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