C/C++ :: Swapping Like Function - Replace Player In A Team

Feb 14, 2015

I have a question about one function in my program. Write a function that will replace players in a team. New player gets in the game, and takes the place of one that leaves. Prototype of function is:

void replace(TEAM *p,PLAYER newplayer,int num)

where second parameter is new player, and the third is a jersey number of player who leaves the game.
Two structures are defined as:

typedef struct {
char name[25],surname[25];int number;
}PLAYER;
typedef struct {
char nameofteam[25];int numberofplayers;PLAYER *players;
}TEAM;

First I tried to read which player should get out, but that didnt work:

printf("which player should get out?
");
do {
scanf("%s",p->players.number)
} while(p->players.number);//Choose one of previously read players

Second thing is to read a new player and replace him with the chosen who leaves.

View 3 Replies


ADVERTISEMENT

C :: Swapping Like Function

Feb 15, 2015

I have a question about one function in my program. Write a function that will replace players in a tim. New player gets in the game, and takes the place of one that leaves. Prototype of function is:

Code:

void replace(TEAM *p,PLAYER newplayer,int num)

where second parameter is new player, and the third is a jersey number of player who leaves the game.Two structures are defined as:

Code:

typedef struct{ char name[25],surname[25];int number;}PLAYER;typedef struct{ char nameofteam[25];int numberofplayers;PLAYER *players;}TEAM;

First I tried to read which player should get out, but that didnt work:

Code:

printf("which player should get out?
"); do { scanf("%s",p->players.number) } while(p->players.number);//

Choose one of previously read players Second thing is to read a new player and replace him with the chosen who leaves.

View 2 Replies View Related

C/C++ :: Access The Swapping Function?

Nov 22, 2014

Giving the following program, how do i access the swapping function. I've tried swapp::change <int> ( a, b ) ; and it gave me 4 errors. Here's the code:

#include <iostream>
using namespace std;
template <typename T>
class swapp

[Code].....

View 5 Replies View Related

C++ :: User Defined Function - String Related Program (swapping)

Jan 4, 2015

Write a program using user-defined function which is passed a string and that function should cycle the string.(Do not use any string related functions). E.g.

If the string is : Chetna then it should print as Chetna, hetnaC, etnaCh, tnaChe,naChet, aChetn

Ans.

#include <iostream>
using namespace std;
char swamp(char a[], int x) {
for(int k=0; k<=x; k++) {
char l= a[x]; a[x]= a[0]; char p=a[x-1]; a[x-1]=l;
for(int i=1; i<x-2; i++) {

[Code]...

View 19 Replies View Related

C :: How To Add Matches And Update Team Struct

Jan 21, 2013

Ive got a football league program that I made to handle 10 teams. Ive got the 10 teams and it displays the league with 0 for played, won, drawn, lost and points but im having trouble actually adding matches to this? How do i add matches and update the team struct?

View 4 Replies View Related

C :: Replace String Function

Dec 23, 2014

I am new to C, but I recently completed an exercise from a book that finds a string in another string, removes the string, and replaces it with another string.

Code:

// Replace String
#include <stdio.h>
#include <stdbool.h>
bool replaceString (char source[], char s1[], char s2[])
}

[code]....

View 8 Replies View Related

C++ :: Find And Replace Function For Text Editor

Jan 3, 2013

I'm building a find and replace function for my text editor I'm building the function without support from the algorithm header.

The function is written like: doc.find_replace("Word_to_be_replaced", "The_word_that_is_replacing"); I find this very easy to understand replace this, with this.

find_replace will both have char * as their arguments.

The problem I'm having right now if I replace a bigger word for a smaller word how do I delete the extra characters from memory.

So if I replace "Goodbye" with "Hello" how do I delete the last two characters? So I don't print garbage code.

View 1 Replies View Related

C++ :: Function To Replace A File With The Contents Of Another Stream

Apr 26, 2012

I have function which will replace (or create) an file with the contents of another stream. The stream could be anything. The replacement is done safely.

Code:
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
int do_replace(const char *file, int stream, int cnt) {

[Code] .....

View 14 Replies View Related

C :: Swapping Some Numbers In String

Jun 15, 2013

I have a pointer to a pointer to a C string:

char**objectData;

In this string there are some numbers with a dash between them, for example, "5-10". I need to read these numbers in and then increment them. So "5-10" becomes "6-11", "6-11" becomes "7-12", etc.

So far I have:

Code: char temp[350]; //350 chars is plenty enough

// Copy the first characters BEFORE the numbers into a new char array. The next characters are the numbers.
strncpy(temp, *objectData, 39); The next steps are:
- Extract the two numbers from the C string (determining if the number is 0,2 or 3 digits long) and write them into two ints. I'm stuck here.

- Increment the ints

- Write the ints into the array with a dash inbetween.

View 6 Replies View Related

C++ :: Swapping Elements In Array?

Nov 25, 2014

I thought I'm done doing mg activity, but my professor said that we need to use a Temporary Variable for Swapping but where to put it.

Here is his activity:

Activity: Swapping Create a program that accepts a 10-element array of type int. Where the 1st user-input is stored in the 1st element of the array; the 2nd user-input is stored in the 2nd element of the array; so on so forth until the last user-input stored in the last element of the array. Your source code should be able to SWAP the values of the 1st and 10th; 2nd and 9th; 3rd and 8th; 4th and 7th; and 5th and 6th elements. It should display the values of the original and the swapped values of the array. example:

Enter 10 integer values:
array[0] = 1
array[1] = 2
array[2] = 3
array[3] = 4

[Code]....

View 1 Replies View Related

C++ :: Swapping Letters In Array

May 3, 2013

I have a function that is suppose to swap positions of 2 letters but It doesn't seem to work. Im passing in the array of char into the function.

void swapletter(char word[]) {
char temp1;
int swap1;
int swap2;
cout<<"What is the first location: ";
cin>>swap1;

[Code] ....

View 6 Replies View Related

C :: Swapping Structures Inside File

Apr 9, 2013

I tried normal swapping method like this (counter is number of structures written in file) :

Code:
fopen("books.txt","r+");
system ("cls");
for(i=1;i<counter-1;i++){
for(j=1+1;j<counter;j++){
fscanf(f," %[^,], %[^,], %[^,],

[Code] ....

But it doesn't do anything.

View 2 Replies View Related

C# :: Swapping Multi Usercontrol In 1 Winform?

Jul 29, 2014

So basically, I started out with each wizard == 1 winform, but then I found another way to do it by making the content of each wizard step a user control, then say, on initial deployment, it load usercontrol1, then when i click next, the panel hide usercontrol1 for usercontrol2 and so forth. Would it be feasible to create all usercontrols (all the wizard step) and add them in an array, then i can load them by index?

View 7 Replies View Related

C/C++ :: Swapping Of Position Of Elements In A Sequence

Oct 24, 2013

Write a program that gets a sequence of unsigned integers.the user can enter at most 100 integers.

After getting the numbers, the program allows the user to repeatedly choose one of the three options:

1. swap the location of two entries in the sequence. if this option is chosen the user is prompted to enter the two locations to be swapped.

2. print out the sequence.

3. repeatedly swap two locations in the sequence until getting back to the state before this operation started. then print out the number of swaps performed.

View 3 Replies View Related

C++ :: Swapping Two Adjacent Linked Lists Nodes

Oct 22, 2014

I am working on a program where I sort elements into alphabetical order and then when one is less than the other I swap them. I first did it by swapping the data but they want me to swap the nodes instead and I am having trouble doing that.

Node *add_node( Node *list, const string &s ) {
struct Node *n = new struct Node;
n->word = s; // copy string s to word
n->next = 0;

// add node n to the list
// the list should always be in ascending alphabetical order
n->next = list;
list = n;

[Code] ....

View 2 Replies View Related

C++ :: Swapping Nodes In Doubly Linked List?

Nov 15, 2014

I've been working on this linked list priority queue . I know that the root of the problem is in my swapUp() function (swapping the positioning of two nodes based on their priority), because the list works great up until it is called. The seg fault is not actually being caused by swapUp(), it's being caused by peekAt(), which returns the element in the node at position n. But the error does not occur unless swapUp() is called first, so that is where the issue is (I think).

There is also a seg fault being caused in the destructor, which I believe may have the same root cause in swapUp().

PRIORITY QUEUE:

#ifndef JMF_PriorityQueue
#define JMF_PriorityQueue
#include <iostream>
#include <string>
template <typename T>
class PriorityQueue{

[Code] .....

Okay, so I've tried implementing SwapUp() in a different new way, but it's still giving me the same problem

template <typename T>
void PriorityQueue<T>::swapUp(Node * target){
Node * partner = target->next; //Partner = target next

[Code] .....

This is such an elementary logic problem I don't know why I'm having so much trouble with it.

View 4 Replies View Related

C/C++ :: Swapping Elements In A Struct Dynamic Array

Dec 1, 2014

Let's say there is a document which stores data of exams of 3 subject. The document is in the below format:

Subject code [spc] Student code [spc] Exam score [endl]

Repeatedly, there are 100 data. E.g.

ENGL_S12 [spc] 000001 [spc] 90.5
ENGL_S12 [spc] 000005 [spc] 77.3
MATH_G22 [spc] 000502 [spc] 100
LATI_F11 [spc] 002005 [spc] 65.4
...

Now I have to write a function show_exam_descending(Data d, string subCode)
when I call show_exam_descending(d, "ENGL_S12")
the program will execute to show all the students' exam scores in ENGL_S12 in DESCENDING order...

For this to run, I have declared a struct Data:

struct Data {
string subjectCode;
int studentCode;
double examScore;
);

For the search, I have written a function before to load all the data from the document by using pointer and dynamic arrays. It works so well. What troubles me is the way to swap the elements (i.e. examScore) of different students in struct dynamic arrays. I am able to display all of them, but don't know how to swap.

View 8 Replies View Related

C++ :: Simple AI That Follows Player

Apr 10, 2014

I'm having some problems with implementing an AI. It should be just a simple AI that follows player. Here is the code that I got so far:

(float)DirectionX = Circle->GetX() - AI->GetX();
(float)DirectionY = Circle->GetY() - AI->GetY();

(float)Hyp = sqrt(DirectionX * DirectionX + DirectionY * DirectionY);

DirectionX /= Hyp;
DirectionY /= Hyp;

x += DirectionX * 3;
y += DirectionY * 3;

This is what I got so far. It creates a vector in a direction I want to move, then just normalizes the vector. Simple as that. But I'm having 2 problems..

AI moves towards player only when Im at like the end of screen and the AI is on the other side, I must keep a certain distance for it to be able to move towards me. Basically, its not constantly moving towards the player. I also tried it with trig, using atan2 for angle and sin / cos for speed. Also didn't work, same result.

The other problem is when I want to add i.e 5 more AIs. For each new AI it creates, it makes a new update.. So, to kinda clear it up. If I'm in middle of the screen and an AI is spawned above me, it will move towards me. But when after that one, 2nd AI spawns beneath me, both 1st and 2nd AI move up. Basically, previous AIs take the update from last one that is created. For updating I'm using lists, objects and iters.

View 3 Replies View Related

C# :: Three And Four Player Uno Game

Feb 26, 2015

I'm having some problems figuring out 3 and 4 player games in an Uno game I'm working on. I'm not sure what specifically the problem is, however. I've tried everything I can think of; I'm at a loss for what to do next. Two player games work perfectly, which makes the nonfunctional 3 and 4 player games seem odd to me. Here is the code:

public void MoveOpponents() {
if (nextPlayer == 0) {
if (Main.dir == Direction.Clockwise) nextPlayer = 1;
else nextPlayer = numPlayers - 1;

[Code] .....

The code for the human player is in Update(), but I won't show that because it's actually quite similar to the above code.

Right now what it's doing is jumping all over the place, making opponent 2 play before opponent 1, then I play, then opponent 1 plays. Then I play again. It's really messed up.

View 6 Replies View Related

C++ :: Giving Score To Correct Player

Jul 22, 2013

I have programmed a game where you guess a number (1-6) and if the number is equal to the random number then give the player score + 10. But if I have selected for example 4 players then if the game will give player 1 a score it gives player 2 a score instead? What can be causing this error?

Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int cube;
int number[4];

[Code] .....

View 6 Replies View Related

C++ :: How To Make Minimax Multi Player

Nov 29, 2013

I have pseudo code for the minimax algorithm but i was wondering what i would need to add to make it work with many players (n players)?

score minimax(state s, int n)
if (n = 0 OR s is a terminal node) {
if win position for program
return +inf;
if loss position for prg

[Code] ....

View 3 Replies View Related

C++ ::  SDL2 / Player Not Moving Constantly

Feb 16, 2015

Im using SDL2 but I'm encountering an unexpected error. I have implemented the same method to move as in my old Projects, but the Player appears to be stuck...

The Player is stuck for maybe half a second, and then everything works as it should, but every time I Change direction or i start moving the Player is stuck for a short Moment.

#ifndef _PLAYER_HPP_
#define _PLAYER_HPP_
#include <iostream>
#include <string>
#include "SDLGameObject.hpp"
class CPlayer : public CSDLGameObject

[code]....

View 9 Replies View Related

C++ :: Two Player Tic Tac Toe Game - Use Enums When Possible To Represent Values

Apr 19, 2013

Here is the code I have written so far. My problem is that when the second user enters its position the last user's position is wiped of the board. I want to know how I can hold that position and keep doing so until the game is finished. I thought that calling the previous function would do that (and you can see where I have put that into a comment) but it doesn't.

Code:
#include <iostream> //includes header file
using namespace std;
//function prototypes
void printLeftUpper(int i, int j);
void printMiddleUpper(int i, int j);

[Code] ....

View 1 Replies View Related

C :: Create Labyrinth And Player Who Needs To Go Through The Map Collecting Objects

Jan 1, 2015

I actually need to create a labyrinth and a player who needs to go thru the map collecting objects (like bags, water etc...). I planned to do the map with a bidimentional array (5x5) but I dont know how to put different objects on an index.. Ex: array[3][2] will have a Botte of water and an energy bar..

Someone told me to use structs but I dont really understand how this would work... I've tried so many times bit I cant do it...

View 2 Replies View Related

C :: Create Structure That Stores Player Name And Score

Aug 8, 2013

We are told to modify this code following the instructions given within the code. It is a tictactoe program.

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// Create a structure that stores a player's name (up to 20 characters) and score (# of wins)
// Call the struct Player

void info(void) {
printf("

[Code] ....

I've ended up with the following code, but the part about the name of the datafile is giving errors upon running the program.

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// Create a structure that stores a player's name (up to 20 characters) and score (# of wins)
// Call the struct Player
typedef struct {

[Code] ....

View 4 Replies View Related

C# :: Program To Run Media Player With Saved Playlist

Oct 26, 2014

Is C# or any other programming language out there that can run like a program that has been installed on you PC? For example say i want my program to run Media player with a saved play list, run spotify, or run a search on the internet?

View 4 Replies View Related







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