#string help

15 messages · Page 1 of 1 (latest)

fading canyonBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

hallow matrix
#

ime and prezime are just pointers, and they point at nothing specific, you can't use them to fill memory

#

there is a significant difference between char* and char[]

#

char[N] will give you N bytes of modifiable memory, which you can fill in

#

so you would need to do something like

    char ime[30], prezime[30];

and then in scanf do scanf("%29s\n%29s",ime,prezime)"

#

notice lack of &, it's because name of array can be used as a pointer to it's first element, and scanf takes just that

#

;compile | 3 imeTEST prezimeTEST

#include <stdio.h>

int main() {
    int number1, number2, x, choice;
    char ime[30];
    char prezime[30];

    printf("Type Number from 1 to 3\t");


    printf("1-Calculator 2-Petlja 3-Ime Prezime "); //Choice
    scanf("%d", &choice);


    switch(choice) {
    case 1:
    printf("Unesite prvi broj: ");
    scanf("%d", &number1);
    printf("Unesite drugi broj: ");
    scanf("%d", &number2);
    if (number1 > number2) //What number is bigger or smaller
    {
        printf("%d je vece od %d", number1, number2); 
    }
    else if (number1 < number2)
    {
        printf("%d je manje od %d", number1, number2);
    }
    else if (number1 == number2)
    {
        printf("%d su jednaki %d", number1, number2);
    }    
    break;
    case 2:
    printf("Unesite broj x manji od 100: "); //for loop 
    scanf("%d", &x);
    for (x; x <= 100; x = x+1) {
        printf("Trenutni x jeste: %d\n", x);
    }
    break;
    case 3:
    printf("Unesite Vase Ime i Prezime: \n");
    scanf(" %s\n", ime);
    scanf(" %s\n", prezime);
    printf("Vase Ime je %s a Prezime %s\n", ime, prezime);
    }
    return 0;
}
analog tinselBOT
#
Program Output
Type Number from 1 to 31-Calculator 2-Petlja 3-Ime Prezime Unesite Vase Ime i Prezime: 
Vase Ime je imeTEST a Prezime prezimeTEST
fading canyonBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

fading canyonBOT
#

This question thread is being automatically marked as stale.

fading canyonBOT
#

<@undefined>

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.

dusk inlet
#

wtf happened here

hallow matrix
#

I have no clue my guy. it's only us now

#

maybe the guy got banned and all his messages got removed ?