C++ :: How To Use Strings In A Function
Mar 26, 2014
None of my string is coming out onto my output file..
void OutputHeading (ofstream& fout, string CLASS_EXERCISE,
string PROGRAMMERS_NAME);
void OutputDivider (ofstream& fout, int WIDTH,
char symbol);
void OpenFiles (ofstream& fout, ifstream& fin);
[Code] .....
View 1 Replies
ADVERTISEMENT
Dec 3, 2014
I am writing a driver program that will eventually need to pass two strings to a function I am writing in a separate file. I am reading data from a file that is formatted like this:
ac: and
amo: love
amor: love
[Code].....
Only a few of the words are actually being processed in the way I want. It appears that only words followed by a comma are processed correctly.
View 1 Replies
View Related
Sep 7, 2013
I have a 2D array with 108 strings. How do I shuffle it correctly?
Code:
void Shuffle( char dest[208][13] )
{
// Initialize variables
char temp[13];
// Loop and shuffle(swap array values)
[Code] .....
The program force closes.
View 6 Replies
View Related
Jul 9, 2014
I made my own function to search if two given strings in my function are equal but the problem is if i pass two variable like hello,hello ... result is string equal but if i pass hello , hello also give me string equal because last 4 characters same to last 4 characters of hello ...
Code:
int getSimilarityOfTwoStrings(const char str1[],const char str2[]){
int str1Len = getStringLength(str1);
int str2Len = getStringLength(str2);
int i = 0;
int j = 0;
bool truefalse;
[Code] .....
View 3 Replies
View Related
Apr 11, 2014
I'm trying to make a calendar and I don't know how to cin strings into an array's index inside a function.
This is my current program.
Code:
#include<iostream>
#include<string>
using namespace std;
void viewMonth (string month[], int num);
void dayNote (string month[]);
int main()
[Code].....
View 1 Replies
View Related
Sep 6, 2013
I have a function that concatenate the strings in an array(2D)
Ex 1: Sean Connery Micheal King James Wood
Result: SeanConnery MichealKing JamesWood ...
The concatenation function working correctly and displays correctly in the function. But if I make another function to display it, it shows this
Ex 2: SeanConnery Sean MichealKing Micheal JamesWood James..
It adds to first name. Why?
Code:
void Concatenation( char dest[200][13] ) {
// loop through and concatenation the strings
for(int i=0;i<200;i+=2) {
myStrCat(dest[i],dest[i+1]); // mystrcat is equalto strcat()
[Code] .....
View 4 Replies
View Related
Apr 11, 2014
I'm trying to make a calendar and I don't know how to cin strings into an array's index inside a function.
This is my current program.
#include<iostream>
#include<string>
using namespace std;
void viewMonth (string month[], int num);
void dayNote (string month[]);
[Code] .....
How do I make void dayNote function work so I can cin a string into the desired array index?
View 3 Replies
View Related
Sep 30, 2013
I need to create a function using rot to encrypt certain strings the function begins like this
#include "encrypt.h"
std::string encrypt (std::string text, int rot) {
for (int i
and ends like this
return NULL;
}
dont need to write the string encrypted and dont need to crate a decrypt function.
View 4 Replies
View Related
Jan 19, 2012
The following code fails/crashes in the second loop where it prints the content and frees the memory. But the issue could be with the first loop.
int main(int argc, char *argv[]){
char **a, buf[80];
int x;
a = (char **)realloc(NULL, sizeof(char *));
for(x = 0; x < 5; x++) {
[Code] .....
View 3 Replies
View Related
Dec 6, 2014
My code so far
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
[Code]....
I keep getting these 3 errors :
error expected '=', ',', ';', 'asm' or '__attribute__' before '{' token|.
error expected '=', ',', ';', 'asm' or '__attribute__' before '{' token|.
error expected '{' at end of input|.
View 4 Replies
View Related
Feb 15, 2012
I have the following function I would like to convert to work with std:string. I don't understand QT strings at all.
Code:
void FromHexString(const QString &hexText, void* pData, int dataSize) {
for (int i = 0; i < hexText.length(); ++i) {
bool ok = false;
((uint8_t*)pData)[ i ] = hexText.mid( 2*i, 2 ).toInt( &ok, 16 );
}
}
View 1 Replies
View Related
Sep 23, 2014
I am creating a doubly linked list that will store strings, for example:
struct node{
string data;
node* next;
node* prev;
};
node* head; //first element from left to right (global)
node* tail; // last element from left to right (global)
And here is the function:
void deleteNode(int n){
struct node* temp1 = head;
if (n == 1){
head = temp1->next;
free(temp1);
[Code] .....
View 3 Replies
View Related
Apr 7, 2013
I am programming a translator, and I have it so that it detects words with spaces both in front of and behind them, so I did "string.append(space);" where space equals " ". That added a space to the end, but I still need a space added to the front.
View 1 Replies
View Related
Feb 12, 2014
I have a problem who must print the sentences who have lenght more than 20 characters. I dont know why, but it prints just the first words. Look what i made.
#include<stdio.h>
#include<conio.h>
int main()
[Code]....
For instance :
Give the number of sentences : 3
First sentence : I like the website bytes.com
Second sentence : I like more the website bytes.com
Third sentence : bytes.com
After I compile the program it should print the first two sentences.
View 2 Replies
View Related
Nov 16, 2013
I tried to add 2 or more strings together but failed.
eg I would like to add "KK" & "LL" together by adding but it couldn't work.
string string_B = "KK";
string string_C = "LL";
string_A = string_B + string_C;
View 2 Replies
View Related
Mar 5, 2013
1. I finished reading a beginning C book, and in the section about arrays, it says that one string can fit in a character array (char arrayname[]) but there cannot be a string array (string arrayname[]) that have multiple strings. Is
Code: string arrayname[4] = {"one", "two", "three"}; not valid?
My compiler lets me run it and it works, but why is the book saying it's wrong?
2. I know you can represent multiple strings in a character array by:
Code: char newarray[10][4] = ("one", "two", "three");
because [10][4] indicates that there should be four newarrays created with a max of 10 characters each, but is
Code: string multiplestrings[10][4] = ("i love you", "hello come to me", "i don't get C"; "hello world", "what are arrays"; "i am happy", "I am learning how to code"); valid?
Does multiplestrings[10][4] basically create 4 string arrays that have a maximum of 10 different strings within each string array?
View 6 Replies
View Related
Dec 14, 2014
How join two strings? basic reason is add given filename little text to end. I try do by hobby not school project program which converts files format x to format y.i dont say which formats becouse reading and writing is almost done. (only little amount code is needed).'
View 2 Replies
View Related
Feb 9, 2015
javascript:tx('quote')
void family () {
string father;
string mother;
string kids;
int x;
int y=0;
[Code] .....
How am I allowed to but the 3 strings father, mother and kids in a array?
View 3 Replies
View Related
Jul 3, 2013
I've got a very simple but annoying problem.
if (letter3=="
"){
letter3==letter;
PrintCharacterLineEnd();
This is a code. the string "letter3" contains the string "
". What I want to happen is when, letter3 contains the text "
" I want to go to the function PrintCharacterLineEnd.
However, as of right now it's not working.
View 14 Replies
View Related
May 19, 2013
I need to make a small program with a function with this prototype: void f(char *a,char *b) that adds two numbers represented as strings without using conversion operators or other tricks.
View 17 Replies
View Related
Apr 10, 2013
why all strings are always constant?
View 2 Replies
View Related
Apr 19, 2012
I have a vector I want to add book titles to, then i want to print my updated vector. This is best I have come up with but the program fails at the getline line. why?
string book;
cout << "Enter book to add: "<< endl;
getline(cin, book);
books.push_back(book);
for(int i = 0; i < books.size(); ++i) {
cout << i+1 << ". " << books[i] << endl;
}
View 1 Replies
View Related
May 3, 2012
The problem with this code is that there are no errors showing, but when i compile the program, the if else statements do not carry out as they should do. Both if statements show the same answer, for example the second if statement. If I type Y or N then I get the same thing, 'You will now choose an event'. How do i get rid of this problem? Is char supposed to be used or string?
#include <iostream>
#include <iomanip>
#include<stdlib.h>
[Code].....
View 1 Replies
View Related
May 14, 2012
How would I alphabetize this with the different strings? Would I just need to use a bubble sort?
Code:
#include <iostream>
#include <string>
#include <fstream>
[Code]....
View 11 Replies
View Related
Nov 8, 2014
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
[Code] ......
How do I link the strings to the integers?
View 4 Replies
View Related
Jan 4, 2014
I am trying to figure out how to go about comparing two strings of numbers. I have two files that both contain numbers 1-50, one file has multiple repeating numbers while the other one just has 1-50.
I want to compare the files and count how many of each number a occurred and make a chart with * next to the number. First I figured I would use the strings like an array and compare them using nested loops. Then I noticed I have single and double digit numbers. The numbers in the files are printed as:
1 44 5 34 4
2 22 7 55 4
...... etc
Compared too:
1
2
3
4
5
......
50
I thought about using string stream and converting the string to int but wouldn't it just be a huge number when set to the int variable? Then I thought about a array initialized with 1-50 and compared to the file but I still have the issue with single and double digit numbers.
My question is how can I just read one number at a time, either double or single digit?
View 11 Replies
View Related