I want an an array called "message" that I can fit 125 characters into and I want to be able to print that array to a text file.
Here is what I have tried: -
char message[125];
-
cout<< computera <<": ";
-
cin>> &message[0], &message[1], &message[2], &message[3], &message[4], &message[5], &message[6], &message[7], &message[8], &message[9], &message[10], &message[11], &message[12], &message[13], &message[14], &message[15], &message[16], &message[17], &message[18], &message[19], &message[20];
-
FILE *retrieve;
-
retrieve=fopen("C:\\Program Files\\NetMessage\\retrieve.vbs", "w+" );
-
fprintf( retrieve, "Const ForWriting = 2\n\nSet objFSO = CreateObject(\"Scripting.FileSystemObject\")\nSet objOutFile = objFSO.OpenTextFile(\"");
-
fprintf( retrieve, path );
-
fprintf( retrieve, computerb );
-
fprintf( retrieve, location );
-
fprintf( retrieve, "\", ForWriting)\n\nobjOutFile.WriteLine (\"");
-
fprintf( retrieve, message );
-
fprintf( retrieve, "\")");
-
fclose(retrieve);
-
Don't worry about the other bits, I am writing VBScript to a .vbs file, but I need to print "message" in there. It is a mix of C and C++ because I am using header files from both languages for various reasons.
The problem is that it only works if the user enters one word into "message" e.g. Hello, but if the user enters anything with any spaces it doesn't like it e.g. This is a test.
2 1290
I want an an array called "message" that I can fit 125 characters into and I want to be able to print that array to a text file.
Here is what I have tried: -
char message[125];
-
cout<< computera <<": ";
-
cin>> &message[0], &message[1], &message[2], &message[3], &message[4], &message[5], &message[6], &message[7], &message[8], &message[9], &message[10], &message[11], &message[12], &message[13], &message[14], &message[15], &message[16], &message[17], &message[18], &message[19], &message[20];
-
-
(abridged by commenter)
-
...The problem is that it only works if the user enters one word into "message" e.g. Hello, but if the user enters anything with any spaces it doesn't like it e.g. This is a test.
Rather than trying to read-in every character singularly, use the "getline" function of "cin". For example, the code: -
#include <iostream>
-
-
using namespace std;
-
-
int main (void)
-
{
-
char message[125];
-
-
cout<<"Message: ";
-
cin.getline(message, 125);
-
-
cout<<endl<<"You typed: "<<message<<endl<<endl;
-
-
return 0;
-
}
-
will read and store (up to 125 characters) everything the user enters until the "return" or "enter" key is pressed (whitespace included). Try using getline() and see if that fixes your problem.
Rather than trying to read-in every character singularly, use the "getline" function of "cin". For example, the code: -
#include <iostream>
-
-
using namespace std;
-
-
int main (void)
-
{
-
char message[125];
-
-
cout<<"Message: ";
-
cin.getline(message, 125);
-
-
cout<<endl<<"You typed: "<<message<<endl<<endl;
-
-
return 0;
-
}
-
will read and store (up to 125 characters) everything the user enters until the "return" or "enter" key is pressed (whitespace included). Try using getline() and see if that fixes your problem.
Yep it has. Thanks for your help.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bob |
last post by:
I've tried everything; and I can't seem to get past this VERY
(seemingly) simply problem.
I want to work with an array variable within a function(s).
I can't get it to work; if I:
1) global...
|
by: Ellen Manning |
last post by:
The main report shows all medical conferences for a resident by year,
by month. A resident can attend many of the same conferences in a
year. In the year footer, I have a subreport that summarizes...
|
by: ritchie |
last post by:
Hi all!
Still working on this program!
Just to recap, I am writing a program to sort an array with four
different sort algorythms.
I am having a little trouble at the moment though!
Now, I...
|
by: Eric Lilja |
last post by:
Assignment: Create a 3x4 2-dimensional array of integers. Populate each
element using some non-random scheme so that no two elemens contain the
same value. Then create two functions for printing...
|
by: skumar434 |
last post by:
Hi everybody,
I am faceing problem while assigning the memory dynamically to a array
of structures .
Suppose I have a structure
typedef struct hom_id{
int32_t nod_de;
int32_t hom_id;
|
by: Cliff Martin |
last post by:
Hi,
I am reading a fairly large file a line at a time, doing some
processing, and filtering out bits of the line. I am storing the
interesting information in a struct and then printing it out....
|
by: arnuld |
last post by:
/* C++ Primer - 4/e
* chapter 4- Arrays & Pointers, exercise 4.28
* STATEMENT
* write a programme to read the standard input and build a vector
of integers from values that are read....
|
by: Jromero |
last post by:
I have a problem with printing the array
Here is the print out
Picture a vehicle number 1 : What's it's max speed?
|
by: serave |
last post by:
Hi, i need some help printing a mutlidimensional array, i can do it
for square Matriz MxM but i need to print an MXN matrix.
here is my code :
function printMatrix($matrix){
echo "<table...
|
by: Keith Thompson |
last post by:
Victor <vhnguyenn@yahoo.comwrites:
You're declaring an array of pointers to unsigned long long, but
you're initializing the pointers with integer values. This is
actually a constraint...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |