C++ :: How To Put End Of String Mark At The End Of Each Line In Array
Oct 28, 2014
Basically I am writing a program that will ask the user to input some names and then I will sort the names. However, right now when I input the characters, it prints out everything, including the empty spaces. How do I put an end of string mark at the end of the line, when the user hits enter
void main() {
constintMaxNames(20);
constintMaxLetters(15);
charNames[MaxNames + 1] [MaxLetters + 1];
intNumRows;
[Code] .....
View 1 Replies
ADVERTISEMENT
Mar 7, 2014
How can a mulitline string be read line by line
ex: str = "PERIOD="week"
DAY="day"
TIME="time"";
View 2 Replies
View Related
Jul 5, 2013
I have a text file (test.txt) with the following data:
01,05,25,20130728
01,06,25,20130728
01,07,25,20130728
01,08,25,20130728
01,05,25,20130728
01,05,25,20130728
01,05,45,20130728
01,05,65,20130728
01,05,85,20130728
01,05,35,20130728
01,05,25,20130728
01,05,35,20130728
I want to read this to one string called line. So far I have this code:
string line;
ifstream myfile ("/home/Test.txt");
if (myfile.is_open()) {
while (myfile.good()) {
getline (myfile, line);
for (int a = 0; a <= 335; a++) {
cout <<line.at(a);
} }
myfile.close();
}
so far its only printing the first line and then throwing an instance of 'std::out_of_range'
View 2 Replies
View Related
May 12, 2014
I have to read the information about logic gates from a file. The file format is shown below:
Code:
gateOne = NAND(inpA, inpB)
gate2=NAND(1,2)
3 = NAND(23,25,26)
As, it can be seen from the above structure that whitespaces are not same everytime. So, to deal with this situation, i am using boost library to remove all whitespaces from the line which is being read and then try to find the name of gate and its input. My code is given below which is able to correctly find the gate names and its first input...but my code is not able to find the second, third and so on input names.
Code:
//C
#include <stdio.h>
//C++
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <boost/algorithm/string/erase.hpp>
[Code] ....
View 3 Replies
View Related
Feb 5, 2014
how the '?' works at the end of the "int luhn" function ( sum += odd ? digit : m[digit]; ) and at the end of main ( printf( "%s
", luhn( buf )? "Valid" : "Invalid" ); ).
I know it's determining what results to report, but the usage is not clear to me. I guess what I'm asking, since I'm not familiar with the use of '?' here, is what the if/else equivalent of these two lines would be.
Code:
#include <stdio.h>
#include <string.h>
int luhn(const char* cc)
{
const int m[]= { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9};
[Code]....
View 3 Replies
View Related
Mar 13, 2013
This code, asking to mark both the smallest and the largest element. I just got largest, didn't get smallest number. Here is code:
#include <iostream>
using namespace std;
int main() {
const int CAPACITY = 1000;
double values[CAPACITY];
int current_size = 0;
[Code] .....
View 9 Replies
View Related
Sep 29, 2013
Program that reads 10 students marks and display the average, the maximum and the minimum marks.
Code] ....
#include <Stdio.h>
main(){
// Local Declarations
int marks[10];
int i; /*loop counter */
int avg;
int sum = 0;
[Code] ....
In this program i am able to get Average Marks and Minimum Marks But i am not able to get the Maximum Marks Output correct.
View 6 Replies
View Related
Jan 26, 2013
Write a program to read in a sequence of examination mark from a text file named as input.txt and produce the mean, and standard deviation of the marks. Your program should also produce a bar chart for each grade where the range of mark is given as below.
GradeMarks Range
A80-100
B70-79.9
C50-69.9
D40-49.9
F0-39.9
Output the result to another text file named as output.txt.
View 3 Replies
View Related
Feb 3, 2013
I want to take multiple line string in c++. How can I take this.
Such as I want to take this as input:
HELLO MY LOVE, I M HAPPY BECAUSE SOON I WILL BE TO YOUR SIDE.
THIS TIME WITHOUT YOU HAS BEEN ETERNAL.
I INVITE YOU TO THE ZOO ONE TO SEE THE ZEBRAS AND GORILAS.
View 2 Replies
View Related
Sep 11, 2014
void login() {
//username, password, option to register, option to exit, link to website
cout << "Would you like to login(1), or press anything else to register.?" << endl;
cin >> loginYorN;
if (loginYorN == 1) {
cout << "Please enter your username: ";
cin >> accountInfo[1];
[code]...
So as above, I ask them to input 1 for login, anything else for register. Whatever they input, it get's stored into loginYorN, then I check to see what they input. If they put '1' for input, then I ask them for their username, store that into accountInfo[1], and then asking for the password, storing that into accountInfo[2].
Now here is where I need to input line 1(username) from login.csv or login.txt and line2(password) and storage these into accountID and accountPW.
View 1 Replies
View Related
Mar 6, 2015
How can i display a string per line on the .txt i made? There are 2 .txt files, the one has: John Finn Xach The other is: password1 password2 password3 Question is: How can i display, let's say, i input "John" so it will display something like this "John's password is password1" or if i input Xach, "Xach's password is password3" When i use something like :
Code:
while(getline(passwordFile, str))
{cout<< username <<" password is " << str;
break;
}
It will work for when i input "John", but it doesn't work if I input "Finn" or "Xach"
EDIT: I tried this one:
Code:
while(getline(userFile, str1) && (passwordFile, str2))
{
cout<< str1 <<" password is " << str2;
break;
The output would be: Finn password is password1
It iterates the username but not the password.
View 7 Replies
View Related
Mar 28, 2014
I'm making a game that requires the user to enter a correct username and password to play. I have a list of accepted ones saved in a txt file. How do i read each line of the file and check it with the one entered? I know how to use strcmp(string1, string2). I just need to know how to move from one line to the next. This is what I have for this part of the program so far. Also, I think im using the feof() wrong.
Code:
id = fopen("F://CS223/namepass.txt", "r");
score = fopen("F://CS223/scores.txt", "a");
srand(time(NULL));
if(id == NULL)
{
printf("ERROR");
[Code] .....
View 6 Replies
View Related
Aug 4, 2014
I try to learn string class, resolving some problem, but i have some dificulties.The is ok, but when i print the longest string it does'n print on the same line.I enter the number of string, after that i enter the first string until i introduced from keyboard "#" character. I enter the second string and so on.Look at these example :
For i = 3;
Text[0] : I learn class String#
Text[1] : I dont learn class String#
Text[2] : String#
It print me like that : Text[1] :
I dont learn class String More than that look at the next example :
For i = 3;
Text[0] : I learn class String#abcdef
Text[1] : I dont learn class String#
Text[2] : String#
You see that in the first sentence i have continue to introduce some characters after # character and look what is happened :
Text[1] : abcdef
I dont learn class String
#include<iostream>
#include<string>
using namespace std;
int main() {
string text[100], cuvant;
int i, j, m, lung = 0;
cout << "
[code]....
View 3 Replies
View Related
Oct 7, 2012
I am working on a project were I have to read line form ( PLC ) programmable logic controller generated text file with lines like this
Circuit Value Current 2.33 4.32 5.55
there could be up to 3000 lines per txt file
I am using string stream to parse the line, for the sake of good programming I which to check weather first three values are string and last three values are actually floats raise or throw an exception if they are not ....
View 4 Replies
View Related
Dec 2, 2013
I'm trying to get this programme to work but I can't get it to output the string data at the end of the line.I have copied and pasted the line in question below but it may be a prob with the prog further down.
It reads character input ok but doesn't put one string into another or recognize when a string is quoted in a printf.
Code:
printf("%s what is your second name?
", surname, name2, name);
#include <stdio.h>
int main ()
{
char name[20];
[Code] ....
View 8 Replies
View Related
Jul 10, 2013
My program takes in an input file from the command line and converts the string from the file into a linked list and then depending on the command it will manipulate the string to either reverse the list, print the list, or take a character out...I'm having trouble taking a character out, my code compiles fine but doesn't change the string at all
Code:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 1024
[Code]....
View 4 Replies
View Related
Jul 8, 2014
I used the following code. I called a method named lets_draw
private void lets_draw() {
int i,z;
z = 40;
Line[] line = new Line[20];
for(i=1;i<=10;i++) {
[Code] ....
But it showed the following message
"An unhandled exception of type 'System.NullReferenceException' occurred in SkeletalTracking.exe
Additional information: Object reference not set to an instance of an object."
View 1 Replies
View Related
May 24, 2013
I have three questions concerning the below code I have written, which is expected to do basically as the attached diagram illustrates:
Code:
#include <stdio.h>
#include <stdlib.h>
double getAverageGrade(int studentGrades[] , int size);
int* getStudentInfo(int * numCourses);
int main()
[Code] ...
(1) How may I display the averages to 2 decimal places, namely why doesn't %.2lf work? The program gives 89.00 for 89 and 90, for instance.
(2) How may I read the number of courses and the relevant grades in a row for each student?
(3) How may I free (de-allocate) my array of pointers, namely grades? Does it suffice to use free(grades)?
View 12 Replies
View Related
Nov 4, 2013
I want to input the elements of a two dimensional array in the same line . So while giving input . when i press enter . it should remain on the same line ? HOW to do that ?
View 1 Replies
View Related
Apr 23, 2014
I am writing a program for AES Encryption which is all but done as far as that the program encrypts the text and prints the encrypted text in the command prompt:
void main() {
int a;
unsigned char CipherKey[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
unsigned char PlainText[16] = {0x32, 0x43, 0xF6, 0xA8, 0x88, 0x5A, 0x30, 0x8D, 0x31, 0x31, 0x98, 0xA2, 0xE0, 0x37, 0x07, 0x34};
for(a=0;a<16;a++)
[Code] ....
Encrypted text output on command prompt = 39 25 84 1d 02 dc 09 fb dc 11 85 97 19 6a 0b 32
However, my project asks to "read blocks of data from a data file". Therefore I need to alter the main function to read the following arrays from a data file.
Unsigned char CipherKey[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
unsigned char PlainText[16] = {0x32, 0x43, 0xF6, 0xA8, 0x88, 0x5A, 0x30, 0x8D, 0x31, 0x31, 0x98, 0xA2, 0xE0, 0x37, 0x07, 0x34};
Firstly, I don't know how to take each individual part in the data file to store into each byte in the array i.e. 0x2B into CipherKey[0] of the array.
Secondly, How do I deal with the fact that each byte is in hexidecimal? How should my data file look?
this is what my data file Input.dat looks like at the minute:
0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
0x32, 0x43, 0xF6, 0xA8, 0x88, 0x5A, 0x30, 0x8D, 0x31, 0x31, 0x98, 0xA2, 0xE0, 0x37, 0x07, 0x34
The first line being the CipherKey array and the second being PlainText. I'm not sure if the '0x' or the commas are required.
I basically want to take the data from a file, store them in arrays in the program itself, encrypt the Input array PlainText and create a new file with the encrypted output array stored in it (I will deal with this part of the program after I get the input file done first).
View 6 Replies
View Related
Apr 11, 2014
I need to print all the values in a square 2d array that are above the diagonal line. So if I have this 6x6 array for instance:
{0,0,0,0,0,0},
{1,1,1,1,1,1},
{2,2,2,2,2,2},
{3,3,3,3,3,3},
{4,4,4,4,4,4},
{5,5,5,5,5,5}
I'd have to print the elements in italics. I've tried this:
for (i = 1; i < a.GetLength(0); i++) {
for (j = i-1; j >=0; j--)
Console.Write("{0,-2}", a[i, j]);
Console.WriteLine();
}
with the array mentioned above but for some reason it keeps printing the elements BELOW the line, when I need it to print those above it. I know that for arrays we usually start loops with a value of 0 but seeing as there should be nothing to print at [0,0] I started the loop at 1.
View 2 Replies
View Related
Mar 5, 2013
I need to write a ANSI program to print out each command line argument on a separate line using a for-loop. also it need to print the name of the executable .so far I have
Code:
#include <stdio.h>
int main(int argc, char **argv) {
int i;
printf("")
[code]....
View 1 Replies
View Related
May 7, 2013
l need to write a program which writes out its command line arguments in reverse order one per line. The output from the program should look like this:
% a.out Two roads diverged in a yellow wood
wood
yellow
a
in
diverged
roads
Two
View 9 Replies
View Related
Feb 1, 2015
In class, we have learned how to set up the main method so we can convert command line arguments to integers and utilize them. Here is an example of a method we learned to store command line arguments as integers in an array:
Code:
int main (int argc, constchar* argv[]) {int i;
int a[argc - 1];
// Fill the array with the arguments on the command line
for (i = 0; i < argc - 1; i++){
a[i] = atoi(argv[i + 1]);
[Code] .....
I understand that there are probably better ways to do it than using the atoi function, but for our purposes, the professor said this was okay.
Now, I am being asked to create a separate function to perform the same task (store integers in an array). I was told I would need to declare the array "out in the main program", and that the function would need to take at least 2 arguments: an array, and an array size.
Firstly, what should my return value be? My professor gave a hint that it would be important for me to figure out what the return value is, but I don't see why it would be anything else than void.
Also, wouldn't I need a third parameter? Perhaps the integers that are being stored in the array? (But how would I represent this as a parameter)?
View 2 Replies
View Related
Jun 14, 2012
I want to create template of of Array in order to have possibility use this template for classes Line and Point.
Code:
// Array.h
// Templated Array class containging Ts
#ifndef Array_H
#define Array_H
template <class T=double> class Array {
[Code] .....
View 10 Replies
View Related
Aug 17, 2014
I am trying to read a file line by line and then do something with the informations, so my method looks like this:
Code:
void open_file(char *link) {
FILE *file = fopen(link, "r");
if (file == NULL) {
fprintf(stderr, "Could not open file.
");
exit(EXIT_FAILURE);
[Code] ....
1) The first complain of valgrind is at the line where I use fgets and its telling me (invalid write of size x), but I have allocated my line to 56000 and the read line is shorter, why is there a write size error then :S?
2) at the line where I realloc where I try to shrink the space he's telling me: Address .... is 0 bytes inside a block of size 56000, But I know i need only this space so why is there a write over space error :S??
View 9 Replies
View Related