You want to read a word. For this, you need an array of char
of some pre-defined size. So change
char kalimat;
to
char kalimat[64]; /* Can hold 63 chars, +1 for the NUL-terminator */
Next, you want to scan a word. So change
scanf("%[^\n]",&kalimat);
to
scanf("%63s", kalimat);
The changes made here are
- Usage of
%s
used to scan a word as opposed to %c
which is used to scan a character.
- Removing the ampersand because
%s
expects a char*
, not a char**
or char(*)[64]
.
- Using a length specifier (63, here) in order to prevent a buffer overflow.
Then, if you want to
Captalize the first character of the array/word, use
kalimat[0] = toupper(kalimat[0]);
or
*kalimat = toupper(*kalimat);
Capitalize all characters in the array, use a loop calling toupper
on each index of the array:
int i, len; /* Declare at the start of `main` */
for(i = 0, len = strlen(string); i < len; i++) /* Note: strlen requires `string.h` */
kalimat[i] = toupper(kalimat[i]);
But... you might need to change
getchar ();
to
int c; /* Declare at the start of `main` */
while((c = getchar()) != EOF && c != '\n');
in order to prevent the consle from closing.
Fixed code:
#include <stdio.h>
#include <ctype.h>
#include <string.h> /* For `strlen` */
int main()
{
int i, len, c;
char kalimat[64];
scanf ("%63s", &kalimat);
/* `*kalimat = toupper(*kalimat);` */
/* or */
/* `kalimat[0] = toupper(kalimat[0]);` */
/* or */
/* `for(i = 0, len = strlen(string); i < len; i++)
kalimat[i] = toupper(kalimat[i]);` */
printf("%s", kalimat);
while((c = getchar()) != EOF && c != '\n');
return(0);
}