The problem was you try to put a pointer into an array. In C you cant copy pointers content by using a simple equal.
Here the solution.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void getPositions(char *outPut, int randNo, int guessNo);
void main()
{
char positions[6];
clrscr();
getPositions(positions, 5242, 5243);
printf(positions);
getchar();
}
void getPositions(char *outPut, int randNo, int guessNo)
{
int randNoArr[4], guessNoArr[4];
int c, w, p;
for(int i=4; i>0; i--){
randNoArr[i] = randNo%10;
randNo /= 10;
guessNoArr[i] = guessNo%10;
guessNo /= 10;
//If Number Possitioned Right Place Incress variable c
if(randNoArr[i] == guessNoArr[i]){
c++;
}
}
for(int j=1; j<=4; j++){
if(guessNoArr[j] != randNoArr[1] && guessNoArr[j] != randNoArr[2] && guessNoArr[j] && randNoArr[3] || guessNoArr[j] && randNoArr[4]){
w++;
}
}
if(guessNoArr[1] == randNoArr[2] || guessNoArr[1] == randNoArr[3] || guessNoArr[1] == randNoArr[4]){
p++;
}
if(guessNoArr[2] == randNoArr[1] || guessNoArr[2] == randNoArr[3] || guessNoArr[2] == randNoArr[4]){
p++;
}
if(guessNoArr[3] == randNoArr[1] || guessNoArr[3] == randNoArr[2] || guessNoArr[3] == randNoArr[4]){
p++;
}
if(guessNoArr[4] == randNoArr[1] || guessNoArr[2] == randNoArr[2] || guessNoArr[2] == randNoArr[3]){
p++;
}
sprintf(outPut, "%dC%dW%dP", c,w,p);
}
That's was your code, but i'll compile and ran this following (i removed #include and clrscr();):
#include <stdio.h>
#include <string.h>
void getPositions(char *outPut, int randNo, int guessNo);
void main()
{
char positions[6];
getPositions(positions, 5242, 5243);
printf(positions);
getchar();
}
void getPositions(char *outPut, int randNo, int guessNo)
{
int randNoArr[4], guessNoArr[4];
int c, w, p, i, j;
for(i=4; i>0; i--){
randNoArr[i] = randNo%10;
randNo /= 10;
guessNoArr[i] = guessNo%10;
guessNo /= 10;
//If Number Possitioned Right Place Incress variable c
if(randNoArr[i] == guessNoArr[i]){
c++;
}
}
for(j=1; j<=4; j++){
if(guessNoArr[j] != randNoArr[1] && guessNoArr[j] != randNoArr[2] && guessNoArr[j] && randNoArr[3] || guessNoArr[j] && randNoArr[4]){
w++;
}
}
if(guessNoArr[1] == randNoArr[2] || guessNoArr[1] == randNoArr[3] || guessNoArr[1] == randNoArr[4]){
p++;
}
if(guessNoArr[2] == randNoArr[1] || guessNoArr[2] == randNoArr[3] || guessNoArr[2] == randNoArr[4]){
p++;
}
if(guessNoArr[3] == randNoArr[1] || guessNoArr[3] == randNoArr[2] || guessNoArr[3] == randNoArr[4]){
p++;
}
if(guessNoArr[4] == randNoArr[1] || guessNoArr[2] == randNoArr[2] || guessNoArr[2] == randNoArr[3]){
p++;
}
sprintf(outPut, "%dC%dW%dP", c,w,p);
}
OUTPUT:
T0109059@P90b11c603564 ~/tmp/test
$ ./a.exe
759583832C2272364W2282526P