I have created a char string[100]. I know this array will be big enough for its purpose. The problem is that it often too big. When I print this string array I get the text plus a lot of gobbledygook at the end which I assume is the extra memory at end of string array. How would I approach trimming this using just C.
I suppose I could nest a for loop that adds to a new array that has a size determined by a counter(although this would give a warning being that a VAR is determining size of array) but I suppose there is a much simpler way to do this.
I have two char* that have the same data in (hypothetically).
std::vector<char*> Buff; Buff = Split(Line, '.'); char* A = "data", B; B = Buff.at(0)
Where Split is a function that I made to split a string (Line in this case) into a char* vector, this string contains a line from a file. Line is char* too. The weird problem is when Buff data stored in its 0 position is given to B... because B is equal to A (hypothetically) but when this is compared to do certain functions they doesn't match!
Here an example:
std::vector<char*> Buff; Buff = Split(Line, '.'); char* A = "map", B; B = Buff.at(0) // Buff.at(0) should be "map" and is apparently "map"
[Code].....
NOTE: I didn't use switch to compare Cmd because I want it separately for easier debugging.
Is there something wrong with my codes?? or what happened here with those hex values before the string in my variables?
i have been trying to compare a date format from SYSTEMTIME and a date from a text file(string).But its not working. I tried to change both to string(using osstringstream),char* and int(using sscanf) to do the comparison but with no luck. its pretty simple all i want to do is get the current system date and compare it with the date from the text file. Below is my code:
char szcurrentDate[MAX_PATH] = ""; char szdate_time[MAX_PATH]; SYSTEMTIME st; GetLocalTime (&st); GetDateFormat(LOCALE_USER_DEFAULT,NULL,&st,"yyyy-M-d ",szcurrentDate,MAX_PATH); //current system date //std::ostringstream mm;
[code].....
note : i tried displaying just szcurrentDate and szdate_time they show the date exactly the same. in string,char* or int formats.
The goal is to merge two files of names, sort them and remove duplicates.I've managed to merge the two files into a single char array and sort them with a function so they are alphabetical.I'm having problems removing the duplicate entries from the array. Here is my code:
I am trying to read strings to an char array from an .exe file and then i would check some of the strings, but the problem is that the only thing that is read from the file is the first string (MZ) and an 'square' that is some incorrect character. I am using fread to read from the file. Here is my code:
I am having issues getting this working. This is a simple program that is designed to ask a user if he would like to enter a string, if yes, the user is prompted to enter it and its stored in a char array. User is then asked if he wants to enter another string... Once user responds no, the program outputs the strings and the program ends...
Note: I'm using in.getline(myarray[i], MAX, ' '), to avoid white space problems if user enters a space. Lastly I would like the option of letting user enter any number of strings, but how would you do this when declaring the 2 dimensional char array?
#include <iostream> #include <string> using namespace std; const int MAX = 81; //max char is sting is 80 int main(){ string y_n; bool go = true;
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.
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.
I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.
this is the entire code:
#include <iostream> #include <fstream> #include <string> using namespace std;
[Code]....
at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.
I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.
/* this is my terminal readout joe bob <- nothing is put into (*playerPtr).name, why not? joe bob joe bob seg fault*/ /****************************************************************/ //This is here to show my struct/playerInit
I have a file which contains a year and the name of an associated file to be read. I need to extract the data in the txt file and perform some calculations.
( year data file) 2004 2004data.txt 2005 2005data.txt 2006 2006data.txt
Here is what I do. I first declare "char yeardata" and then pass "2004data.txt" to it. Then I call yeardata in ifstream to extract the data inside the file "2004data.txt". The problem is that char yeardata is not constant so I cannot pass the file to it. It doesn't work if I change "char yeardata" to "const char yeardata".
Code: int oldnewcomp_temp(char* lcfile) { using namespace std;
I am having problems copying outputs of the above code into other unsigned char other[32]. I need to keep the output of dev/urandom for backup. But, when I try to assign the values by memcpy(other, key, 32), the values do not match. The same problem happens by assigning values index by index in a loop.
I'm trying to write a program that takes input from the user (thats a char) and outputs it to the monitor in hex form.The program is meant to continuously take input from the user then output to the monitor in hex form until an EOF is detected this triggers the program to close.The following code does this except that I get a lower case 'a' at the end of each output.
example:
input from user: ABC output to monitor: 41 42 43 a
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:
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?
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).'
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.
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.
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; }
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?