Home > other >  Is there any possible way to move character from one column to another?
Is there any possible way to move character from one column to another?

Time:11-20

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

These are my available libraries. I want to move character from one column to another column of string. I can use scanf to detect which character I want to move and where I want to move the character. Let´s say I have

 char col[][]

That have 2 columns and 2 rows with random characters that looks like this

| a | | .. |

| b | | .. |

And I want to move character "a" to the second column so I have

| .. | | .. |

| b | | a |

Columns and rows can be randomly big

What I need is to make

void move_characters(const int rows, const int columns, char col[rows][columns], int x, int y)
{

}

Note : All I need is to move characters, I already have constucted array with characters in it. I don´t need to move a specific character. I need to move character from the top of that column. Thanks.

| .. | is empty position == ' '

int x = number of column/row, from which I want to move character

int y = number of column/row, to which I want to move character

Characters moves to the bottom of the column or if there already is a character it moves on top of that character.

CodePudding user response:

You said that x was the source and y was the destination right? The thing is that you need two values for each, one for rows and one for columns then you can do something like this:

col[y1][y2]=col[x1][x2]; //Duplicates value from source to destination

Not sure what you mean by empty, there are two empties that come to my mind:

col[x1][x2] = "";  // "Empties" source

or

col[x1][x2] = NULL; // "Empties" source
  • Related