I am writing a program in C that requires us to use arrays and pointers. It reads in four characters and then prints them out in a rotated pattern. For example, if the input characters are ABCD, the output will be (with no leading spaces):
ABCD
BCDA
CDAB
DABC
We also need to write a function RotateFourChars using pointers and a "temp" variable to store c1 (the first character) in order to rotate the characters.
Here is the code I wrote for it:
#include<stdio.h>
#include<string.h>
void RotateFourChars(char *p){
printf("/n%s",p);
char temp;
int j;
int i;
for(i = 0; i < 3; i++){
temp = *p;
//pritnf("\nTemp :%c", temp);
for(j = 0; j < 3; j++){
*(p + j) = *(p + (j + 1));
}
*(p + j) = temp;
*(p + (j + 1)) = '\0';
printf("\n%s",p);
}
}
int main(){
char c[4];
printf("\nEnter 4 charcters: ");
fgets(c);
printf("\nRotated Pattern: ");
RotateFourChars(c);
}
This is the error I keep getting:
In function ‘main’:
lab7.c:22:2: error: too few arguments to function ‘fgets’ fgets(c); ^ In file included from lab7.c:1:0: /usr/include/stdio.h:622:14: note: declared here extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) ^
I'm not sure what arguments I'm missing. Can someone help ? (Sorry if this question is all over the place.)