🔒 Closed Patulong sa code mga lods

Status
Not open for further replies.

ALLMIGHTisHERE

Eternal Poster
#include<stdio.h>

int main(void) {

char a, b, c;
printf("Enter the first character: ");
scanf("%c", &a);
printf("Enter the second character: ");
scanf("%c", &b);
printf("Enter the third character: ");
scanf("%c", &c);



printf("%c\n%c\n%c", a, b, c);


return 0;
}
yung nasa image sana gagawin ko, di ko alam kung bakit di gumagana code ko. Pahelp sana mga lods

Untitled.png
 
Instead na
printf("%c\n%c\n%c", a, b, c);
dapat ganito
printf("%c\n%c\n%c", &a, &b, &c);
Hindi mo nalagyan ng ampersand or '&' symbol yung variables nung nag printf ka. Essential yun if you wan to retrieve the value of the variable during printf calls.
 
Instead na
printf("%c\n%c\n%c", a, b, c);
dapat ganito
printf("%c\n%c\n%c", &a, &b, &c);
Hindi mo nalagyan ng ampersand or '&' symbol yung variables nung nag printf ka. Essential yun if you wan to retrieve the value of the variable during printf calls.
sa scanf yan nilalagay lods
 
1659762066797.png

C:
#include <stdio.h>

int main() {

char a[3][3];
char pos[3][20] = {"first", "second", "third"};
int i;

for(i=0;i<3;i++){
    printf("Enter the %s character: ", pos[i]);
    scanf("%s", &a[i]);
}
for(i=0;i<3;i++){
    printf("%s\n", &a[i]);
}
return 0;
}

C:
#include <stdio.h>
char a,b,c;

int main() {
    printf("Enter the first number: ");
    scanf("%c", &a);
    printf("Enter the secound number: ");
    scanf(" %c", &b);
    printf("Enter the third number: ");
    scanf(" %c", &c);
    printf("%c\n%c\n%c", a, b, c);
    
    return 0;
}
 
View attachment 2068516
C:
#include <stdio.h>

int main() {

char a[3][3];
char pos[3][20] = {"first", "second", "third"};
int i;

for(i=0;i<3;i++){
    printf("Enter the %s character: ", pos[i]);
    scanf("%s", &a[i]);
}
for(i=0;i<3;i++){
    printf("%s\n", &a[i]);
}
return 0;
}

C:
#include <stdio.h>
char a,b,c;

int main() {
    printf("Enter the first number: ");
    scanf("%c", &a);
    printf("Enter the secound number: ");
    scanf(" %c", &b);
    printf("Enter the third number: ");
    scanf(" %c", &c);
    printf("%c\n%c\n%c", a, b, c);
   
    return 0;
}
grabeh lodi, actually nagets kona. Lalagyan ko lang ng space yung %c sa scanf para hindi maread yung \n everytime you press enter. Salamat parin lods
 
pa explain lods bakit kailangan may space, ang ginawa ko kasi naglagay ako ng dalawang scanf tas gumana siya.
mahirap magexplain pero parang ganito
sa first scanf ok lang pero sa pangalawa habang naginput mareretain kasi yun return key o enter (newline) ng una sa buffer kaya nagescape na manghingi ng input kaya para iignore ng scanf dapat may space
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 10
    Replies
  • 1K
    Views
  • 5
    Participants
Last reply from:
FoXOnE23

Online now

Members online
671
Guests online
643
Total visitors
1,314

Forum statistics

Threads
2,276,937
Posts
28,973,181
Members
1,230,626
Latest member
ReiAyanami
Back
Top