C :: String As Parameter Not Working Properly
Oct 19, 2013
I want to alter a string inside a function, but it is not working.Here is the function:
Code:
#include <stdio.h>
void test (char *ch){
ch[0] = 0;
ch[1] = 1;
ch[2] = '';
}
[code]...
View 2 Replies
ADVERTISEMENT
Nov 1, 2014
I am creating a right hand maze solution, and it actually works for the most part, but it gets stuck at the sixth spot and will not proceed any further. I cannot seem to find my error even though I know it's probably a small one in my code, here is what I have at the moment:
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
[Code].....
View 6 Replies
View Related
Jul 3, 2013
I have a slider control on a dialog box. I am playing a video file and slider moves according to the video elapsed. Suppose I have set the slider range to 100. Now till some point say 90, the slider moves to the point wherever I click the mouse. but at the last point in between some range say 90 - 100 (to the end of the slider), if I click the mouse button anywhere, slider jumps to the end.
I am using a TimeLine control where user can add more than 1 video (1, 2, 4, 8, 10 , 50 etc......), If I use only one video, slider moves as per the video progression.....Issue arises when I add more than 1 video and click on the start button, slider starts moving....Now when I drag the slider to any position or I click the mouse button anywhere on the slider control, slider thumb moves to that position and immediately jumps back to some other position. This is the Issue, I am facing.
share some sample code where slider is moving with the video showing the progress of the video.
I want to implement a functionality similar to VLC player. Wherever user clicks the mouse, slider moves to that point.
View 13 Replies
View Related
May 9, 2013
I tested my count funtion. So my count function is not working properly, it should return 5 because 5 words have prefix "tal," but it is giving me 10. It's counting blank nodes.
This is my main.cpp file
int main() {
string word;
cout<<"Enter a word"<<endl;
cin >> word;
string filename;
[Code] .....
View 9 Replies
View Related
Feb 11, 2015
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
class Player {
private:
char name[20];
int score;
[Code] .....
View 5 Replies
View Related
May 30, 2013
I've was trying out a function template to automatically get the type of a lambda, but it seems that it won't compile
I've tried two different ways:
1.
template<class HASHER>
auto make_unordered_map(size_t bucketCount, HASHER const && hf)
-> unordered_map<string const, HASHER>&& {
return unordered_map<string const, int, HASHER>(bucketCount, hf);
} auto x = make_unordered_map(1, [](string const& key)->size_t { return key[0]; });
2.
template<class HASHER>
auto make_unordered_map(size_t bucketCount, HASHER const && hf2)
-> unordered_map<string const, int, decltype(hf2)> {
return unordered_map<string const, int, decltype(hf2)>(bucketCount, hf2);
} auto x = make_unordered_map(1, [](string const& key)->size_t { return key[0]; });
The test code are located here:
1. [URL] ....
2. [URL] ....
They are both based on the code that is stated to work in those examples. I.e.:
auto hf = [](string const& key)->size_t { return key[0]; };
unordered_map<string const, int, decltype(hf)> m (1, hf);
View 13 Replies
View Related
Mar 5, 2013
1. In main() in the while loop entering 'q' does not exit.
2. in the isbnValidation function. The size check for minimum length words will work, but the check for "Invalid ISBN character" doesn't.
3. Every ISBN entered returns as valid. The formula is supposed to multiply the first digit by 10, next by 9 etc (skipping all the dashes) and add up to a weighted total which if valid will divide evenly by 11.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ISBNMIN 10
#define ISBNMAX 14
[Code].....
View 4 Replies
View Related
Sep 2, 2013
I'm reading in a data set using an ifstream, then fetching line by line to a stringstream:
std::ifstream sfile(filename);
std::string test;
std::getline(sfile, test);
std::stringstream sline(test);
(I'm not sure why I used an intermediate string; it's pretty much legacy-code at this point, which I just reuse every time. Still works, so why change it!)
The problem is I'm using two types of data sets now, and the difference is one (optional). Most data files just have an arbitrarily large number if the second must be ignored, but others have nothing.
In the normal case, I'd simply use sline >> d >> L; to extract the parameter values. However, I'm not sure how this line will behave if the second parameter is omitted. Will it read nonsense? How do I check whether or not the parameter was set or not?
View 7 Replies
View Related
Mar 20, 2012
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void interpose(char s[], char a[], int pos) {
char b[80];
[Code] ....
The program should take 2 string parameter and 1 int parameter for combining. (without any str functions, the functions should be written by coder)
My problem is when i enter int value program crashes.
For example,
str1='Good';
str2=' Morning';
int x= 5;
The output will be 'Good Morning'
View 2 Replies
View Related
Feb 21, 2014
why I'm getting an error with this code? I'm trying to pass a string as a parameter and use it to open a file:
class txt{
private:
string tempstring;
vector<string> strings;
char filename[10]; //not using this right now
[code]....
but I get this error:
[Note] no known conversion for argument 1 from 'const string {aka const std::basic_string<char>}' to 'const char*'
I thought strings were just const character arrays
View 3 Replies
View Related
Feb 19, 2013
I know my product.cpp constructor is wrong but how can I set my private variables.
//PRODUCT.h
#ifndef PROJECT1_PRODUCT_H
#define PROJECT1_PRODUCT_H
[Code].....
View 2 Replies
View Related
Feb 18, 2013
Modify your code by adding your own tests to see if your functions work right. Include at least 6 separate tests, of your choosing.
For example, test the compare function with the first parameter as a blank string -- then with the 2nd as a blank -- then both. Test compare with the first string shorter than the second -- then the other way around. Test your copy function with long strings.
I am struggling with how to use the compare function with a parameter as a blank string. I tried leaving the first parameter blank but doing ("",text) but I don't think that is the correct way of doing this.
#include <cstring>
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int myStrLen(const char[]); // return length of null-terminated string stored in char array
[Code] ....
View 2 Replies
View Related
Sep 26, 2013
How to write a printPattern() function?
The function takes in a parameter i.e. a char pointer. It handles the parameter as a Cstyle string i.e. a NULL terminated char array. It does not make use of the stringclass or its associated functions. In other words, the function examines every char element in the array until it encounters the terminating NULL character.
Starting from this int main :
int main() {
char string1[] = "Application of C++";
printPattern(string1);
}
[Code].....
View 1 Replies
View Related
Dec 6, 2014
The function Reverse does seem to work. Its supposed to take the words in a sentence and then reverse them. For example: "This is nice" to "Nice is this." When I type "This is nice" I get " niceniceis nice"
#include <iostream>
#include <string>
using namespace std;
[Code]....
View 1 Replies
View Related
Feb 3, 2013
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void count();
void main() {
char c[100];
cout<<"Enter a string upto 99 characters(spaces included):"<<endl;
[Code] ....
The thing is, when I don't create a prototype of count and straightaway define it before void main() my program runs, but it gives error in this program that "extra parameter in call to count()" But what to do then?
View 2 Replies
View Related
Oct 20, 2013
I've created this little program.
#include <iostream>
int main(int argc, char* argv[]) {
char string1[] = "Hello";
char string2[] = "Hello";
[Code] ....
The idea, was to show that when you compile with the /GF flag set, string pooling is enabled, and the const char*'s which point to string literals would point to the same, read-only memory location. However, the addresses are still different.
Obviously, I'm compiling with /GF set. I'm using VC++2008 IDE if it makes a difference.
View 4 Replies
View Related
Feb 10, 2013
I created a .txt file that I called in.txt. It has the letters: a b c d e. I put it in the same folder as the c++ code below. I was hoping that I after I compile and run the code, the in.txt file would read: e d c b a. Unfortunately, it doesn't. Even when I give the ofstream file another name, it does not create another text file.
Code:
#include<iostream>
#include<fstream>
#include <limits>
[Code].....
View 7 Replies
View Related
Sep 28, 2014
My errors are at the end of the program in two function calls within the definition of the InsertByValue function. g++ does not seem to recognize NumArray as a valid parameter.
#include <iostream>
#include <assert.h>
using namespace std;
const int CAPACITY = 20;
/* Displays the content of an int array, both the array and the size of array will be passed as parameters to the function
@param array: gives the array to be displayed
@param array_size: gives the number of elements in the array */
void DisplayArray (int array[], int array_size);
[Code] ....
View 1 Replies
View Related
Dec 4, 2013
I am developing new project in Qt with existing MFC project . SO in MFC I have a function which uses SYSTEMTime and return CString.
example
CString getTimestampString( void )
{
SYSTEMTIME systemTime;
CString datestr;
[Code]....
PS -> I cant able to make any changes in lib_know as this library is being used by many other projects..
View 1 Replies
View Related
Jul 2, 2013
Here's my function definition
bool validateNumber(string& text, int min = 0, int max = -1, bool useMin = true,
bool getValid = true)
The code takes the string text, and checks the make sure that the input is valid and safe to convert and use as a number. However, sometimes there is not min, and sometimes there is no max. The lack of min is done by using the parameter useMin, while the lack of max is done by max < min.
My predicament is the following call:
validateNumber(text, -2);
Now, max will be used, even though I don't want it. Ideally, I would want to do something like... int max = (min - 1), ... but that doesn't work. I also can't check to see if the parameter hasn't been changed (that I know of), because the following call would make it look like it hasn't
validateNumber(text, -2, -1);
So the question is, is there a way to do what I want, without having to add in a bool useMax parameter? Or is this my only option? I don't want to do that for simplicity, but if I have to, I have to.
View 3 Replies
View Related
Aug 26, 2014
I am unable to get the string seaching function to work. it always says "Nothing found" I am stumped.
Code:
#include <stdio.h>
#include <string.h>
char tracks[][80] = {
"I left my Heart at Harvard Medical School",
"Newark, Newark, You suck balls",
"Dancing with a dork",
"From Here to maternity",
"The Girl from Iwo Jima",
[Code]....
View 3 Replies
View Related
Mar 30, 2013
I have a file which I am unable to read properly. This is binary file so my code is"
#include<iostream>
#include<fstream>
#include<string>
[Code]....
the file to read can be download from this link :
[URL]
The first content of file should be 1 I am missing few content from the begining
View 2 Replies
View Related
Oct 31, 2013
so i have a container called Source that is of type std::map<std::string, std::vector<std::string>> but when I try to print it with this function:
void Lexer::PrintSource()
{
for(auto Iterator = this->Source.begin(); Iterator != this->Source.end(); Iterator++)
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
cout<< *SubIterator << endl;
}
i get these errors:
Lexer.cpp: In member function 'void Lexer::PrintSource()':
Lexer.cpp:29:42: error: 'struct std::pair<const std::basic_string<char>, std::vector<std::basic_string<char> > >' has no member named 'begin'
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
^
Lexer.cpp:29:76: error: 'struct std::pair<const std::basic_string<char>, std::vector<std::basic_string<char> > >' has no member named 'end'
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
^
View 6 Replies
View Related
Sep 29, 2014
#include <iostream>
using namespace std;
int main()
{
[Code]...
For some reason, I get the cout of
321
1
Because of the a++, shouldn't it be
321
2
The second example is what the cout needs to be.
View 1 Replies
View Related
Sep 2, 2013
If I were to exit a program, is it okay if I fail to properly destroy whatever structures were allocated?
For instance, if I do this with SDL, there might be obvious consequences like a dead window perhaps. But if I do this with a POD structure, is it okay?
Also, I realize RAII is supposed to fix parts of this but it's not perfect when environments are suddenly cut off with something like exit(1/0);
View 2 Replies
View Related
Apr 11, 2014
I'm parsing an xml file full of payslips and using the data in another application. I've got it all working but I suspect it isn't the most elegant piece of code. I run through the xml file finding a series of "Text" attributes/elements" and then I run through it again finding a series of "Field" attributes/elements, Here is a sample of the code:
For getting the "Text" fields :
XNamespace ns = "urn:crystal-reports:schemas:report-detail";
//
// Get all the Text attributes & Elements
//
foreach (XElement xtxt in xdoc.Descendants(ns + "Text"))
[Code]...
This works fine, I extract all the data I'm interested in and go to do my thing with it. However I really need to know when each record ends and I was doing that by looking for "Text24" in the text fields and "EeRef2" in the field fields, which wasn't very elegant in the first place. Then a "Text16" was added to end of each record which was fine I could just look for "Text16" but now it's apparent that "Text16" isn't always there. I've got it all working for now but I'd prefer to process one record at a time i.e. extract all the "Text" & "Field" values for one record, do whatever I need to do with it, update the xml file to indicate this progress ( if possible ) and then move on to the next record. I've attached a sample of the xml but basically is has the following structure :
<Details>
<Section>
<Text></Text>
"
<Field></Field>
[Code]...
So a record is everything between the first <Details> and the last </Details> with two <Details> and two </Details> in between.
View 2 Replies
View Related