C++ :: Passing Block Of Char To Variable

Sep 8, 2014

#include<iostream>
using namespace std;
int main(){
int size_col = 12;
int size_row = 12;
char months_array[12][12] =

[Code] ....

I am having problems with passing a block of a char to a variable, so i could print it out.

It gives me an error: value of type *char cannot be assigned to a entity type char.

View 7 Replies


ADVERTISEMENT

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 :: Displaying Text File Block By Block In C#

Dec 21, 2012

I have a text file that is divided into blocks:

#1
1:animal
2:food
3:moves
4:oxygen

#2
1:eats:2
2:breaths:2
3:can:1
4:is a:1

#3
1:1:2
1:3:3
1:2:4

And the following program that displays block by block:

StreamReader streamReader = new StreamReader("G:LAB123LABWORK2.txt");
            int block = 0;
            while (!streamReader.EndOfStream)  {
                string line = streamReader.ReadLine().Trim();
                if (line.CompareTo("") == 0)

[Code] .....

My problem is am supposed to add a verification code so that if i put a string e.g 1:?:? it returns the block where the string is found and gives of all possible answers.

Attached Files : LABWORK2.txt (240 Bytes)

View 2 Replies View Related

C++ :: Type Conversion - Float Or Double Variable Into Unsigned Char Variable And Back

May 10, 2013

I would like to convert a float or double variable into unsigned char variable and back.

float number_float = 23.453f;
unsigned char* number_char = (unsigned char*)malloc(sizeof(float));
number_char = reinterpret_cast<unsigned char*> (&number_float);
float* number_float_0 = reinterpret_cast<float*>(&number_char);

I am not getting the same value back.. why?

View 2 Replies View Related

C++ :: Passing Char Array To Function

Nov 23, 2013

In the below program, When the getline function is called, it passes a char array of size 1000 by VALUE. It must have passed by value because there is no pointer or reference in the argument list of the getline function definition. And if that's the case, when exiting the getline function, isn't the s[] char array destroyed? And if it is destroyed, then when we reference line in the copy function, what are we actually copying?

#include <stdio.h>
#define MAXLINE 1000/* maximum input line length */
int getline(char line[], int maxline);
void copy(char to[], char from[]);
/* print the longest input line */
main() {

[Code] .....

View 3 Replies View Related

C++ :: Passing Char Arrays Between Functions Of Same Class

Nov 16, 2013

I'm having trouble with passing a character array between functions of the same class. I have a function, buildGraph, that calls function getNextLine. The getNextLine essentially just retrieves the next line of an input file and stores it into a "char line[80]". However when I try to use "line" in my buildGraph function, it has nothing in it.

Here's my code:

Class
#define NUMNODES 10
using namespace std;
#pragma once
class Prog3Graph

[Code] ....

View 4 Replies View Related

C :: How To Stop Passing Char Array Index As Pointer

Dec 23, 2013

I am trying to write a light weight printf style function.

I have got this far:

Code:

void println(const char *txData){
LOG(__PRETTY_FUNCTION__);
UARTPuts (LPC_UART0, txData);
}
void miniPrint(const char *format, ...)
{
unsigned int index = 0;
va_list argptr;
va_start(argptr, format);

[Code]....

I understand why I think. When I am passing the reference to the array possion it is outputting everything up to the next /0. So my question is how do I stop it?

I dont have much choice as to how the output wants it:

Code: void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str)

Thats library code, so I dont want to change it. I.e I have to pass an address into println.

View 1 Replies View Related

C :: Passing Variable From Outside Function To Main?

Nov 8, 2013

This code is for a program that allows you to play a guessing game or arithmetic game and shows your total score from both as you go along. The program works fine the only problem I'm having is with the score. Is there a way to call the score value from the outside function into main?

Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
//prototype functions
void menu();

[Code] .....

So trying to pass the value of score from the outer function int guessGame() into the score print statement in choice 3 of the main function? Oh and the "17 -turn_count" was just part of the requirements of the assignment.

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

Visual C++ :: Passing Variant Variable Through LPVOID

Mar 25, 2013

I have create a function which able to return value for variant of variable through a LPVOID parameter function.

Here is my coding.

Code:

void main()
{
CClassA a;
BOOL bAssign=FALSE;
CString str;

[Code].....

View 6 Replies View Related

Visual C++ :: Passing A Variable From CView To CDocument?

Dec 12, 2012

I am attaching a sample project. Basically what this project does is that I initialize a variable map<CString, bool*> m_mapTest in CView::OnInitialUpdate and then pass the variable to CDocument class. On the other hand, within the function OnSaveDocument defined in CDocument I check m_mapTest. To my surprise, the CString part of m_mapTest is correct but the bool* part of m_mapTest is wrong(I pass an array of bool in CView::OnInitialUpdate).

View 3 Replies View Related

C/C++ :: Passing Member Functions Member Variable To Another Variable

Aug 31, 2014

So I have a class object that contains the private member variable spot and the public member function MoveLock. Within MoveLock, is a member variable called numbers that holds the place where a user is on a "lock knob". Now, what I'm trying to accomplish is that whenever the user turns the "knob" in the wrong direction, the position is updated with that current numbers so that the clicks needed to unlock the first state is also updated. But I get these errors:

Error E2096 C:Users...switchtest.cpp 34: Illegal structure operation in function main()
Error E2294 C:Users...switchtest.cpp 39: Structure required on left side of . or .* in function main()

Ultimately, what I have in main() is a piece of what I'm going to implement in a class member function. I'm also thinking about moving the if else statements out of the for and creating a second one for the else portion.

#include <iostream>
#include <windows.h>
#include <iomanip>
using namespace std;
HANDLE inKeys = GetStdHandle(STD_INPUT_HANDLE);
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);

[code]....

View 10 Replies View Related

C++ :: Passing Multiple Variable To Function That Has Stringstream And Text

Dec 24, 2013

I have a quick question about passing multiple variable to a func that has (stringstream & text). Here is the code:

void PrintText(stringstream & txt) {
cout << txt.str() << endl;
}
void main() {

[Code] ....

How to make second one work?

View 11 Replies View Related

C++ :: Debugging Char Variable

Oct 13, 2014

I have a bug and when I debugged in some point i needed to know whats inside my char **grid , when i hold mouse over this variable in debug mode i can only see hex or address.. ! i cant see my values grid is 10 * 10 table which hold a number from 1 to 3 .... is there any way for me to see whats inside ?

I'm using visual studio 2013 ultimate ....

View 2 Replies View Related

C++ :: Char Data Type Variable

Jun 12, 2013

I have two char variables, m_GPSOffset[13] and m_FileName[100]. When m_GPSOffset has a value assigned to it, say for instance +11:25:30. The first entry of the value, in this case +, is always stored in m_FileName. I am clueless on why this is occurring.

View 15 Replies View Related

C++ :: Opening File Using Variable (Char Or Int)

Mar 14, 2013

Can we open a file in c++ using a variable(either character or int)?

View 1 Replies View Related

C++ ::  Initializing Const Char Member Variable In Constructor?

Jan 23, 2015

I have a class that defines a window (a popup dialog of sorts), and I want the name of that window to be constant. The only problem is that the name of the popup needs to match the title of the parent window, and I get the name of the parent in the constructor. So how do I go about defining this member variable to be constant and initializing it with a value in the constructor?

I want to do something like this, but I know this isn't allowed:

/* class.h */
class foo {
public:
foo(*parentWindowPtr);

[Code] .....

I should mention that yes the name of the parent window is const char *, and I would like to keep it this way.

View 4 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++ :: Store Address Of Customer In Char Variable - How To Read A Line With Spaces

Oct 10, 2014

I want to store the address of a customer (with spaces) in a char variable (say cadd). First I tried to use "cin", as we know it reads until it sees any whitespace. So it reads only first word before a white space. So, I used "getline()" function, it will work. But when I used it, It did'nt wait for the I/P (it skipped it).

char cadd[20];
std::cout<<"Enter Customer Address:
";
std::cin>>cadd;
std::cout<<"Enter Customer Address:
";
std::cin.getline(cadd,20);

View 3 Replies View Related

C++ :: Block Internet Access To A PC?

Jun 18, 2012

I need to turn off internet access for SPECIFIC website locations. I use C++ Builder 2010 or Delphi 2010.

View 5 Replies View Related

C++ :: Multiple Comparisons In One Block

Aug 9, 2012

Here's my program bake.cpp(name does not reflect content) I've been researching this binary error and haven't been able to find a solution...

Code:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main() {
//Display a list of options.
cout << "Choose your favorite:" << endl;
[Code] ....

Error code..

1>------ Build started: Project: bake, Configuration: Debug Win32 ------
1> bake.cpp
1>c:usersjonbecherdocumentsvisual studio 2012projectsbakebakebake.cpp(41): error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::basic_ostream<_Elem,_Traits>'

[Code] .....

View 1 Replies View Related

C :: Clrscr Function In Code Block

May 1, 2014

I start working on CodeBlocks and stuck in a situation. The situation is that I want to clear my output screen every time the main function calls some other functions. To do that I use clrscr() function but its not working. After spending some times on web, I found that its a non-standard function so this extension is not used by the new compiler's. Another thing I find to use < cstdlib > library. But unfortunately it do works only for C. It works for C++.

View 2 Replies View Related

C# :: Block Program From Seeing Process Tree

Dec 7, 2011

I have a program that I can only run one instance of. When I try to start it a second time, it doesn't do anything. I would like to create a script that loads the program in a way that I can run multiple instances. Since I assume the program checks the process tree on startup to see if an other instance is already running, I figure disabling access to the process tree could do the trick.

View 6 Replies View Related

C/C++ :: Looping Entire Block Of Code

Feb 3, 2014

I just want my program to run continuously until someone enters 0 to exit it. I tried doing while(x=1) and looping my entire block of code. Also there is a switch one is a for one is a while loop both doing the same function. I have basic error checking and whatnot.

/*This is a program that gets a user to input a starting and ending value.
The code then prints the number ie 1 and 5 would be (1,2,3,4,5) and all the squares and cubes.
There is a case statement asking weather you want to run it as a for or as a while loop.
The choices are case sensitive.
*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>//allows for power and cube function
int x;
int main(){

[Code] ....

View 4 Replies View Related

C++ :: Implementing Signature Block Class

Sep 29, 2013

For class we are required to implement a signature block on all our assignments. To do this I've created a Signature Block class, but I'm having trouble implementing it. When I try to compile in Dev C++ I get this error:

[Error] request for member 'toString' in 'myblock', which is of non-class type 'SignatureBlock()'

Here is the code:

Assignment1.cpp

#include <iostream>
#include <string>
#include "SignatureBlock.h"
// Assignment 1: Requests user's name and says "Hello."
using namespace std;
int main(int argc, char** argv) {
string name;// string to store user's name
SignatureBlock myblock();// create a signature block object

[Code] ....

View 4 Replies View Related

C/C++ :: Illogical Results By Using Try And Catch Block

Oct 24, 2013

there are illogical results by using try and catch block

#include<iostream>
using namespace std;  
class Circle_computations {  
public:
    double area,circumference,radius,pi;  
public:    
 Circle_computations() {

[Code] ....

View 1 Replies View Related







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