C :: Scrambling Words In Array?
Sep 3, 2013
I'm writing a function that scrambles(shuffles) words(strings) in a 2D array. The problem I'm having is that it is scrambing the characters. Not the actual words. I've used trial and error but I can't find what wrong.
Code:
void Scramble( char dest[208][13]) {
for (int i = 0 ; i < 108 ; i++) {
for (int j = 0 ; j < 2 ; j++) {
int m = rand() % 108;
int n = rand() % 4;
[Code] ....
View 2 Replies
ADVERTISEMENT
Dec 20, 2013
I have written below program to count number of words and lines and print the all the words.
#include <iostream>
using namespace std;
#include<fstream>
#include<string.h>
int main() {
ofstream outfile;
[Code] .....
Its compiling fine but when executed its displaying I infinite times...
View 3 Replies
View Related
May 19, 2013
I was reading this earlier [URL] ..... and I was trying to figure out how to pick one of the words randomly from my text instead of using all the words in it.
View 4 Replies
View Related
Jan 26, 2015
I got a homework that require to count number of words in a text file and also display the first and last 10 words of the text file to the console. I have finished the counter problem and now I struggle showing the first and last 10 words.
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
int tokenize(string sentence, string tokenizedWords[]);
[code]....
View 2 Replies
View Related
Apr 16, 2014
I need to compare the words from a text file with words from an array (which i got from another file) and count the instances of those words. I thought about making another array but that doesn't make sense since the text file may have a lot of words in it.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main() {
FILE *myFile;
char words[100][40], test;
[code]...
the test variable in the last for loop is wrong i know i was just trying something.
View 13 Replies
View Related
Apr 24, 2013
Creating a C program that can pick words in a string or array and save it in different location, later combine everything in one string or array. It will be using simple programming C code. For example (arrays, pointer) but not interrupts or other string functions.
In a sentence like this:
Size= 70
$--GSV,x,x,x,x,x,x,x,...*hh $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,b,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh $--GLC,xxxx,x.x,a,x.x,a,x.x,a.x,x,a,x.x,a,x.x,a*hh $--GSA,a,a,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x.x,x.x,x.x*hh
The program must capture the $--GGA string then extract from this string:
1) hhmmss.ss
2) IIII.II
3) a (if a = to N or S replace N or S with + or - respectively )
4) yyyyy.yy 5) b (if b = to E or W replace E or W with + or - respectively )
Save them in an array and display as well. After all the saving, the program should combine them to one string. That the final output.
View 7 Replies
View Related
Sep 15, 2014
I am trying to read in player names (ex: first last) from a text file into the people[].name data struct. I can successfully read in my card file, but I cannot get this to work. I get a seg fault. I believe this is because nothing is actually being read in for my while loops. I can't use std::strings so these must be c-style strings aka char arrays.
// deck of cards
// below are initializations
#include <iostream>
#include <fstream>
#include <ctime>
#include <stdlib.h>
#include <string>
using namespace std;
//globals
const int maxCards = 52;
[Code] .....
View 1 Replies
View Related
Sep 26, 2014
for (Initializing; Boolean_Expression; Update) i'm tying to use the words instead of numbers to repeats ,already i changed( Initializing; Boolean_Expression and Update) it doesn't work ,all i got is just Numbers !!
# include <stdio.h>
main()
{
[Code]....
View 3 Replies
View Related
Mar 6, 2015
I am creating a trie (not a tree but a trie). I have the following structure:
Code:
struct tnode {
bool is_word;
list *children;
};
struct trie {
int length;
struct tnode *first;
};
list *children is a linked list that contain pointers to tnodes. For example: I have a trie with the words cup and cut:
c
u
/
p t
Given the example above you have the following linked lists:
1. [c] that contains a pointer to linked list 2.
2. [u] that contains a pointer to linked list 3.
3. [p, t]
Now I want to print the trie like:
cut
cup
View 2 Replies
View Related
Oct 2, 2014
I am trying to write a program in C to reverse a string .
Example - This is America
output - America is This
I have thought of two ways of doing this question
1) using 2D arrays ( no pointer)
2) Using Strings and pointer
Code:
#include<stdio.h>
#include<string.h>
main()
}
[code]....
View 4 Replies
View Related
Dec 10, 2014
I've tried searching for answers around the web but everyone is using syntax that We haven't been taught before in class yet. I understand that the string library is probably the most efficient way of doing this but is there a way without using that library? Like using if, for, while etc. instead?
I've been told that using anything else other than the string syntax is far to complex but I think the more complex it is the more I will understand it.
View 9 Replies
View Related
Dec 4, 2013
I want to print the words of a sentence, given as a string..But I have a problem with the end of the sentence, and cannot find the bug....
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char str[80]="This is a sentence";
int main(){
}
[code].....
View 7 Replies
View Related
Apr 29, 2014
How to convert numbers into words using ragged dynamic arrays? this is my solution:
int main()
{
char *Units[]={"ZERO", "ONE", "TWO", "THREE","FOUR","FIVE", "SIX","SEVEN", "EIGHT", "NINE"};
char *teens []={"TEN", "ELEVEN", "TWELVE","THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN","NINETEEN" };
char *hundreds []= {"HUNDRED"};
char *tens []={ "ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
char *currency []={"Dollars"};
[code]....
View 2 Replies
View Related
Apr 14, 2013
i am trying to create a c++ program that asks for an input and determines if it is a question or not by searching each word from the input across a database (txtfile)..so far I have managed to make it search the database for the word but it only works on one word.... i would like to be able for it to search every word on the input separatly..here is the code:
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
[code]....
View 4 Replies
View Related
Mar 13, 2014
I am trying to read into a file that has something like
I have 5 apples and 9 bananas.
Sam has 8 apples and 6 bananas.
and I need to replace the numbers with words. For example I need to change the "5" to five and so on. The problem is that im not sure how to access and then replace just the numbers.
#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main() {
ifstream in_stream;
[Code] ....
View 2 Replies
View Related
Oct 21, 2014
This function buildTree that reads an text input (contained in the file named in argv[1]). Then, I am opening the file, reading character by character, if there is a new line ("if (token == ' ')") keep track of this line number and store it in a vector to access it later. Next it breaks it into a sequence of words (using any character other than a digit or an alphabetical symbol as the terminator). This is where I'm getting an error. I am then trying to add each character to a string and then when the token is a digit or an alphabetical symbol, then push the string into a vector so I can access it later. Is my logic right? error when pushing each word into a vector.
BinarySearchTree buildTree (char *argv[]){
ifstream file;
vector<char *> V;
int line = 0;
[Code]....
View 2 Replies
View Related
Aug 3, 2014
I'm currently on an exercise that specifies that I find any repeated words, "the the" for example, in a string, print the word that is repeated and how many times said word is repeated using a while loop that reads one word at a time and break statements when a repeated word is found. Having a bit of a falling out with iterators tonight and I'm not doing to well.
View 7 Replies
View Related
Apr 29, 2014
Write a c++program that asks the user to enter positive integer numbers without points between 0 and 999. Then check the amount and print in words. You need to use dynamic ragged arrays..
This is my solution but I'm not sure if this is the right way for dynamic ragged array???:
int main()
{
char *Units[]={"ZERO", "ONE", "TWO", "THREE","FOUR","FIVE", "SIX","SEVEN", "EIGHT", "NINE"};
char *teens []={"TEN", "ELEVEN", "TWELVE","THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN","NINETEEN" };
char *hundreds []= {"HUNDRED"};
char *tens []={ "ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
[Code].....
View 1 Replies
View Related
Mar 3, 2013
I'm trying extract words from a text file and then put then them into a set. I want to delimit all the spaces as well as the periods. My code is working fine for spaces but its leaving out the periods at the end of some words.
void Dict::get_words(string file){
ifstream file(file);
int end, beginning = 0;
string word;
string line;
[Code] .....
View 3 Replies
View Related
May 21, 2014
I am trying to write a program in which i enter sentences and then gives the reversed output
E.g.: -
INPUT
Enter the number of sentences
3
This is a sentence
Program
You are great
OUTPUT
sentence a is This
Program
great are You
I wrote the following code but its failing when im trying to enter a sentence
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void str(char*, int);
void main() {
char *word[25];
[Code] ....
View 7 Replies
View Related
Apr 19, 2013
I am trying to read text from a file that includes
lastname firstname bloodpressure
for example:
Jones Tom 110/73
determine whether the blood pressure is normal, above normal, or below normal and then create a line that reads...
lastname, firstname has normal blood pressure bloodpressure
For example: Jones, Tom has normal blood pressure 110/73
All I can get is the entire line. I cannot find the correct code to get word for word or int. My code is this...
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main() {
string x;
[Code] ....
View 2 Replies
View Related
Jul 30, 2014
im trying to do is get a huge text file, grab information from it and output into another file, for example the file contains:
userid = xxsfdfafa, name = vinnidrk, product = 12341,
otherfield = 1
otherfield2 = 2
otherfield3 = 4
userid = asdsada, name = anotherperson, product = 424123,
otherfield = 3
otherfield2 = 5
otherfield3 = 1
What i want, is to be able to get the name for every account until end of file and output it one under the other.
vinnidrk
anotherperson
View 4 Replies
View Related
Nov 25, 2013
I am trying to write a code that reads all the words in text according to each sentence from a file. this means i have to signify the end and beginning of every individual sentence the text file. actually am trying to create a summarizer in c++.
View 5 Replies
View Related
Feb 3, 2015
"Type a function that take in a string containing numbers and others characters and print on stdout all the numbers contained into the string, where for number is mean every maximal numerical sequence, of numbers not separed by spaces. Numbers printed on exit must be separated by commas. For example, if i put in the function the string "paje27hg78 2k f562" my function must print:
27, 78, 2, 562 "
So i started my code like so: (I WANT TO NOTICE THAT WE HAVE ONLY USED IOSTREAM AND FSTREAM LIBRARY FOR NOW, SO DON'T USE OTHERS LIBRARY ELSE MY TEACHER WON'T CORRECT MY HOMEWORK!)
#include <iostream>
#include <fstream>
using namespace std;
[Code].....
View 18 Replies
View Related
Dec 31, 2014
This what I'm trying to do:
Type two or more lines of text into a file. Write a program to open the file, reading each word into a vector<string> object. Iterate over the vector, displaying it to cout. That done, sort the words using the sort() generic algorithm
But I'm stuck unfortunately.
#include <iostream>
#include<fstream>
#include<vector>
#include<cstdio>
using namespace std;
int main() {
ifstream infile("about.txt");
[Code] .....
Error: 'about' was not declared in this scope
View 1 Replies
View Related
Sep 22, 2014
Problem i have is that is keep saying "error: file". I have test.txt. Byway i am using xcode 6 and I using C.
#include <stdio.h>
/* counts words in the file */
int main(void) /* C89 ANSI */
{
FILE *fp;
int r; /* a variable for result of a function, returning int */
size_t n; /* the words counter */
[Code] ......
View 5 Replies
View Related