C :: 2D Array With 108 Strings - Shuffle Function?

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


ADVERTISEMENT

C++ :: Member Function To Shuffle Content?

Nov 14, 2014

Is there member functions for STL's like vector,list etc., to shuffle the content of that STL.

eg:

int arr[] = {1,2,3,4};
std::vector<int> v1(arr, arr+ sizeof(arr) / sizeof(int) );

now i need to shuffle the data randomly like

Now vector may contain {3,2,4,1} or {2,1,4,3} ...

I have taken vector as an example. let me know if there is any alternative way with other STL's

View 2 Replies View Related

C++ :: Create Array Of Playing Cards / Assign Values And Suits Then Shuffle The Array

Nov 24, 2014

I got this program to create an array of playing cards and assign the values and suits and shuffle the array. I'm at the point where I need to output the cards but I need to burn the first card by making it output "**" instead of the card. my cards[] is a constant so I can's assign the first card as such.

void showCards(const int cards[], int numCards, bool hideFirstCard) {
if (cards[0]) {
hideFirstCard=true;
cards[0] = '**';
} for(int a = 0; a <= numCards; a++) {
cout >> showCard(cards[a]);
} }

View 1 Replies View Related

C++ :: Writing Strings Into Array Index Within A Function?

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

C :: Concatenate Strings In Array (2D) - Function Not Working Right?

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

C/C++ :: Writing Strings Into Array Index Using Function

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

C++ :: How To Shuffle A Vector (cards)

Mar 2, 2014

I am trying to write a sub-program that takes a deck of 52 cards and will shuffle it up using this algorithm:

Start with n=51
Repeatedly:
Generate a random integer between 0 and n. Call it i.
Swap card i and card n in the deck.
Decrease n by 1

However the code that I've written,

vector<int> shuffleDeck(vector<int> deckVector)//deckVector is the original deck in order
{
int temp, n, i, s;
n = 51;

[Code].....

when I output the new vector, only produces this output(note- it is a random number every time, but it just repeats over and over):

8 8 8 8 8 8 8 8 0 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8

or:

22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 0 22 22 22 22
22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22

View 1 Replies View Related

C++ :: How To Shuffle A Word Coming From A File

Sep 24, 2013

HOW TO SHUFFLE A WORD COMING FROM A FILE?

FILE *DOCU;
DOCU = fopen ("file.txt", "r");
if (DOCU == 0) {
printf ("
Failed to open!

[Code] .....

View 4 Replies View Related

C/C++ :: Shuffle Songs Into Random Order

Sep 26, 2014

What's wrong with my shuffle function? It shuffles some songs, yet completely gets rid of others.

Here's the code:

void shuffle() //Shuffles songs into a random order. {
Music temp, temp2; //Temporary music file holders, 'Music' is a struct with string title;, string artist;, and int size;.
unsigned int currentTime = (unsigned)time(0);
srand(currentTime);
for (int i = 0; i < NUM_SONGS; i++)

[Code] .....

I want it to output this:

1. Title: Runaway2, Artist: Bon Jovi2, 2 MB
2. Title: Runaway5, Artist: Bon Jovi5, 5 MB
3. Title: Runaway1, Artist: Bon Jovi1, 2 MB
4. Title: Runaway4, Artist: Bon Jovi4, 1 MB
5. Title: Runaway7, Artist: Bon Jovi7, 5 MB
6. Title: Runaway6, Artist: Bon Jovi6, 5 MB
7. Title: Runaway3, Artist: Bon Jovi3, 5 MB
8. Title: Runaway8, Artist: Bon Jovi8, 1 MB

Or something along those lines, but instead I get something like this:

1. Title: Runaway7, Artist: Bon Jovi7, 1 MB
2. Title: Runaway2, Artist: Bon Jovi2, 2 MB
3. Title: Empty, Artist: Empty, 1856312448 MB
4. Title: Runaway4, Artist: Bon Jovi4, 1 MB
5. Title: Runaway5, Artist: Bon Jovi5, 5 MB
6. Title: Empty, Artist: Empty, 0 MB
7. Title: Runaway7, Artist: Bon Jovi7, 1 MB
8. Title: Empty, Artist: Empty, 1856312448 MB

View 2 Replies View Related

C :: How To Shuffle Bits Of Plain Text According To DES Standard

Jul 14, 2014

I learned the bitwise operations in c, but how to shuffle the bits of the plain text accoring to DES's standard. Even with the key and the S-boxes. How DES is performed in C step by step. I have a fair knowledge in C.

View 3 Replies View Related

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 View Related

C++ :: Pass Two Strings To A Function?

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

C :: Function To Search If Two Given Strings Are Equal

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

Visual C++ :: Create A Function Using Rot To Encrypt Strings

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

C++ :: 2-Dimensional Character Strings And Realloc Function

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

C :: Can Strings Fit In Array

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

C :: Converting Two Strings To Upper And Lower Case Using Function

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

C++ :: Convert QT String Manipulation Function To Work With Strings?

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

C :: Array Of Pointers To Strings

Mar 6, 2015

I'm wondering how to access Buffer 1 and 2 via the pointer array;

Code:
char *BufPtrs[3];
char Buffer1[64];
char Buffer2[64];
BufPtrs[0] = Buffer1;
BufPtrs[1] = Buffer2;
BufPtrs[2] = NULL;

I thought that if I were to access Buffer1 via BufPtrs[0], I would simply just put an * to it before printf()-ing or store it in a char[] (equivalent to a string).

View 2 Replies View Related

C :: Storing Strings Into Array

Mar 27, 2013

I am having trouble storing strings into an array. Basically I have a console program where it has an option. This is just an example;

Code:
char name[max];
char listofnames[maxname];
int counter;
....
printf("Add names
");

And how can I print it?

View 9 Replies View Related

C :: How To Shift Strings Down In Array

Feb 23, 2013

I am having this problem were the user types in a substring to search in the main string and replace it with another string

for example:

string: hello
sub string: el
replace: i

should print this: hillo

I tried using some string functions but I am having problems with that.

View 7 Replies View Related

C++ :: How To Output Array Of Strings

Feb 5, 2013

How do you use a for loop to iterate through strings to display them in a console?

View 3 Replies View Related

C++ :: How To Unite 2 Strings In Array

Sep 26, 2014

#include<iostream>;
using namespace std;
int strlen(char []);
void strcat(char S1[], char S2[], int size_1, int size_2);
const int SIZE = 100;
const int MAX = 100;

[Code]...

i have been trying to do a function that unites strings entered by user, i need to do this without any other libraries but i keep getting an output of the first word and dots.

View 5 Replies View Related

C/C++ :: How To Input Strings Into 3D Array

Feb 19, 2014

I was very much confused with managing the 3d arrays. Other than initialising it is tough for me to input the data into the 3d array at runtime. I have tried the every possible method i know untill now but i can't successfully input and output the data.

I have written a code by declaring the 3d array of char s[5][2][20] in main and passing it's base address into another function, lets say input(char (*p)[2][20],int ,int ,int). I have passed the 3 dimensions in declaration 5,2,20 to the input function i have used these 3 values as the subscript for the pointer p and tried to input the data. But i wasn't successful.

How to input the strings into the 3d array.

My preferences were:

1.The change of subscript value should take place in loop(eg:for).
2.Which indexes should be used for inputing the data through pointer.
3.Use either "scanf" or "gets" function to inputs the data and print using "printf" or puts.

View 1 Replies View Related

C++ :: Doubly Linked List That Will Store Strings - Delete Function

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

C :: How To Convert From Array Of Chars To Strings

Jan 13, 2014

As a part of a program I am supposed to write, I would like to receive a string from the user (for example: "Hi my name is Joe").

obviously, the string is inserted to an array of chars (arr[0]='H', arr[1]='i', arr[2]=' ',... and so on).

What I would like to do, is to put each word separately in each array cell (for example arr[0]='Hi', arr[1]="my"..., and so on). How can I do this? (I can not use any functions, unless I write them myself).

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved