C :: Char Array With A Phrase To Char Word
Nov 28, 2013I need to do a function that copy every word from a text to a char word. How can i do it?
View 5 RepliesI need to do a function that copy every word from a text to a char word. How can i do it?
View 5 RepliesLet's say i have some text in char array Code: char text[] = "Hello my friend"; How can i get a seperate words from it? It should be like
Code:
char a[] = "Hello";
char b[] = "my";
char c[] = "friend";
Is it possible to do?
I'm writing a function that accepts a char array containing the title of a book as parameter, the following then has to take place:
1.) Extra white spaces between words need to be removed [DONE]
2.) Text has to be converted to title case, i.e each new word has to start with a capital letter [DONE]
3.) Lastly I have I text file (minors.txt) containing a number of words that should not be capitalized by the function, like "a" and "an", however I don't know how to implement this.
Example of end product:
ENTER THE TITLE OF THE BOOK: a brief hisTOry OF everyTHING
Correct Output:
bool Book :: convertToTitleCase(char* inTitle) {
int length = strlen(inTitle);
bool thisWordCapped = false;
//Convert paramater to lower case and
//Remove multiple white spaces
for (int x = 0; x < length; x++)
[Code]...
I was thinking of maby reading the words in the text file into a string array, and then comparing the two arrays to ensure that when a word is present in a text file, the word is not capitalized, however I don't know if that is possible between a string array and a char array.
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
[Code]....
The code below replaces lowercase characters by upper case and uppercase character by lowercase. Also, I should be able to break out of the loop when I enter 'exit'. It does what it is supposed to do. But I had to come up with a function to break out of 'the while loop'. Is there any shorter or more concise way to break out of the loop when 'exit' is entered?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
[Code]......
Code:
cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())
[Code] .....
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;
int year;
char yeardata;
[Code] ....
I have an int array with the binary value of a char. How to to turn it into a char? I can transform it to an int but then I'm stuck.
Code:
#include <stdio.h>
int main() {
int a[260] = {0,1,1,0,0,0,0,1};
char buf[260];
int b=0;
for(int i=0; i<8; i++) {
b=10*b+a[i];
}
itoa(b, buf, 10);
Code:
#include <stdio.h>
char * strcpy(char *restrict s1, const char *restrict s2);
struct item {
char title[20];
struct item *next;
} firstCard;
int main (){
strcpy(firstCard.next->title, "whatever");
}
I am unable to set firstCard.next->title
I have some code:
char cHomeTeamFaceOffsPercentageWon[100];
memcpy(cHomeTeamFaceOffsPercentageWon,cSqlHomeTeamFaceOffsPercentageWon,100);
After this, for example, cHomeTeamFaceOffsPercentageWon is, "29%".
Then, I use
std::string szwPercentageWon = std::string(cHomeTeamFaceOffsPercentageWon);
szwPercentageWon is then, "2". Shouldn't this convert correctly, to "29%" as well.
Or is there something I'm missing? Maybe the termination character, or something.
I like to use a Pointer to char array. And then I would like to do a Pointer Arithmetic by incrementing the Pointer. Finally I would like to see the Addresses of the Pointer to each of the char Array Elements. I had created a program below, but I am not getting any Addresses from my Pointer.
#include <iostream>
using namespace std;
int main () {
int ArraySize;
char ch[]= "This is a Char Pointer";
char* iPtr = ch;
[Code] ....
I have this code:
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
ifstream f("input.txt");
ofstream g("output.txt");
[Code] .....
This program make a copy of the source array, then it removes each character and shows the obtained array.
And when i insert "abcdefghijkl"
it should show this: "
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
ifstream f("input.txt");
ofstream g("output.txt");
[Code] .....
I am working on a program to find uppercase, lowercase and digits in a 2D char array. When I try to use an if statement to increase the counter, I get an error "no conversion from 'int' to 'char*'". This is the if statement I am using.
if(myArray[j] <='9' || myArray[j] >='0')
I want to assign a char to an array inside an if statement after the user has input the grade as an integer, but it has to fill an array with characters, such as:
char grades[5];
int grade;
char A, B, C, D, F;
cout << "Enter da grade" << endl;
cin >> grade;
if (grade < 59) {
grade[0] = F;
[code]....
A, B, C, D, and F won't transfer to the array, thus giving me the uninitialized variable error in microsoft visual studio 2010.
I want to convert int to char array for get the total of digits like this..
Code:
int total;
char charnum[2] = (char)total; //this is the problem
int num = 0;
for (int i = 0; i <2; i++)
{ num += charNum[i] -48;}
cout << num;
If total was 42 i want to get output as 6. for this purpose i want to convert int to char.
I wrote this simplified version of a program i am writing that parses data in UDP packets. In the process of doing so i pretty much answered all my questions and fix all the problems i was having.
decodeSystemMap function will be in loop, and will proccess packets that have mostly the same data, only a few items will be added or changed or deleted.
whats the best way to check if there are any new, deleted, or removed items in the packet and only modify those?
Is there anything unsafe / dangrous about the way the code is now?
Code:
/* * File: main.c
* Author: david
*
* Created on May 23, 2013, 11:57 AM
*/
#include <stdio.h>
#include <stdlib.h>
[Code] ....
The following is something I am not clear about. Multi dimensional char arrays and the displaying of them.
Code:
#include <iostream>
using namespace std;
main() {
//char test[5][5]
[Code] .....
The commented out expression didn't run at all but the double quotation mark one did, unfortunately, it gives me a hexadecimal display. How can I get it to display like this:
*****
*****
*****
*****
*****
I am working on a c-programm. In this program I have to convert the amount of money I read on two variables into the corret format. I got Euros and cents on 2 ints. But now I want to add both of those variables in a String (char array). Also i want to find out the length of the new char array.
View 2 Replies View RelatedIn this program, I have to ask the user for an employee, then the program will check to see if the file for that employee exist, if it doesnt then it will automatically create the file.
ReadNew function reads the file....check to see if it exist
CreateNew function creates a new file.
In my code I have no problem with the first part of reading file.. and my createnew function works in other programs where I am asking for input of file name to create the file name. However in this code I cannot figure how to automatically pass the input filename from the ReadNew function to the CreateNew function. I can't ask the user to enter the name a second time, so I have to pass the input filename into both functions. Here is my code.
Code:
//Create a file, append to it, and read it.
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
using namespace std;
char filename[256];
string n;
string filelist;
void CreateNew(ofstream & FileNew);
[Code]...
Alright, so I have a code that's not giving me errors, but it doesn't seem to retain what I put into an array. Not sure If I'm missing something...
Code:
#include <stdio.h>
int main (void)
{
const char *pointer;
const char alphabet[] = "ABCDEFG";
pointer = &alphabet[5];
printf("pointing to %c of the alphabet
", pointer);
return 0;
}
Trying to get my pointer to return the letter in the [5] spot or "F". Not receiving any errors when compiling, but I seem to get different answers every time I run it.
Code:
#include main() { char why[64]; why =255,255,255,255,255,255,255,255;
while (why > 4); printf("why is equal to" ,why); why = why-2;
return 0;
}
It tells me incompatible data type.
I'm having trouble returning a char array by a function, here's the code. The problem is the 'reverse' function, the purpose of the function is to send two char arrays, 'newline' containing the char array, reverse it and place it in the 'rev' char array then output it back in main, however the output remains blank so I assume there must be something wrong with the reverse function.
Code:
#include <stdio.h>
#define MAXLINE 10
int fgetline(char line[], int maxline);
void copy(char to[], char from[]);
void reverse(char forw[], char rev[], int arrsize);
[Code] .....
Currently I have:
Code:
char my_array[4] = { '1', '2', '3', '4' };
how do I convert the above to a string of: "1234"
I'm trying to fill the array "g" with letters from the array "letras" given a certain condition. Everything is working fine, except I couldn't do it... Strange characters appear when I run the code. What am i doing wrong?
Note: This is a part of a function. "vetor" is a parameter that was passed to this function.
Code:
int i;
int j = 0;
char g[20];
char letras[5] = {'a', 'b', 'c', 'd', 'n'};
while(j < g)
{
for(i = 0; i < 80; i = i + 4)
[Code]...
.I have this string that I need to convert into a 2d char array like this:
String str= "A,E,B,I,M,Y#N,R,C,A,T,S";
I know how to use delimiter and split string and I know how to convert but only from string to char[].I need something like this:
Input: String str= "A,E,B,I,M,Y#N,R,C,A,T,S";
Output: [A] [E] [B] [I] [M] [Y][N] [R] [C] [A] [T] [S]