Questions tagged [swap]
The swap tag has no usage guidance.
14
questions
0
votes
1
answer
4k
views
How to swap elements in "struct" data type?
I am working on "tideman" from pset3 and stuck on sorting the data that i have in "struct" data type.
Don't really know if it was supposed to be figured out on our own, but they ...
0
votes
1
answer
35
views
How to swap strings?
The main problem comes when we swap strings of unknown lengths. Lets say we have two strings assigned to two variables say a, b. Now if I use a temporary string say c, and use strcpy(c,a), then use ...
0
votes
1
answer
22
views
About the functions
Why does this code not work?
I want to understand why I need to create copies of a and b.
I understood the whole idea, but the creating process is not clicking with me.
0
votes
1
answer
103
views
Pset3 (Game of Fifteen): The tiles won't swap... ("Illegal move")
I have an issue with my code in Game of Fifteen. I get "illegal move" when I try to swap the tiles, even if it's a "legal" tile. I tried everything but I really don't understand what's wrong. Does ...
0
votes
1
answer
23
views
I have written this swap code but it is not compiling, Where's the bug
while compiling error says insert ')'at void swap(&a,&b);
I can't understand this error
here is the code
#include <stdio.h>
#include <cs50.h>
void swap (int* x,int* y);
int main (...
1
vote
1
answer
26
views
Why function free() is not working here
In this swap function, free() is not working in the last line for temp variable, what am I doing wrong.
#include <stdio.h>
# include <stdlib.h>
void swap (int* x,int* y);
int main (void)
{...
0
votes
1
answer
86
views
Pset3 selection sort only correctly swaps the first value
I have a question about selection sort code I implemented. Specifically, my swap function seems to be swapping only the first value in a list of numbers through each loop. For example, if I have the ...
-1
votes
1
answer
49
views
Swap() with bit operations only
There is a way to write a swap function using only bit operation and no temporary variable, but I can't get mine to work. Any help?
0
votes
1
answer
66
views
week 4 walkthrough swap
void swap (int *a, int *b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}
I want to know if int tmp = *a, "*a" means an int value, then
*a = *b, both *a and *b become pointers, ...
0
votes
1
answer
297
views
Cannot implement swap function for fifteen pset3
I managed to write a swap function before attempting "fifteen" , but within the context of writing the "move" function, I just can't get it to work, despite following the same format.
When I swap, it ...
1
vote
1
answer
477
views
Swap 2 and 1 after looping, pset3, Game of Fifteen
I don't know why my positions at 2 and 1 in my odd numbered tiles are not swapping. Here is a mix of pseudo code plus my swap conditional. See anything that is wrong? Thanks.
// board, whereby ...
0
votes
0
answers
311
views
Swap function in helpers.c file
I have successfully completed the linear search and sort functions in the helpers.c file for problem set 3. I included the swapping steps within the sort function directly and everything worked ...
1
vote
2
answers
1k
views
How can I swap two values and return two integers?
I wanted to write a function that swaps two values, but I'm not sure how to return 2 integers. This code doesn't work, as after swapping the values x is still one and y is still 2:
void swap(int in_1,...
0
votes
1
answer
537
views
helpers.c is not sorting my array and I'm running low on ideas on how to fix it
My first question on this board and I really need some help in order to figure out what could be wrong with my code. I decided to go with a a selection sort but as soon as I run ./generate 2 2 in ...