Can anyone assist in a resolution of a C code?

Asked

Viewed 241 times

0

Next guys, I’m studying and I’m Beginner, and I have this resolution to solve and I’m having a hard time... I have to use scanf("%[^\n]%*c", s), where s is an array of char... The code must read two terminal data, a character set (up to 100 characters) and an integer value and display them in the console.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char s[100];

    printf("Nome\n");
    printf("3");
    scanf("%[^\n]%*c", s);
    return 0;
}

The code is like the one I put in, I got him to read the data, in case nome and 3 by default, why the user does not need to type, plus the part of the scanf I can’t.

The data entry has to be typed in the same code ta alie above, because the parts of the printf ta right.

name

3

Output expected one below the other so but the exit does not automatic that...

name

3

2 answers

1

Simple task.

#include <stdio.h>
#include <stdlib.h>

int main()
{
  int numero;
  char nome[100];

  printf("*\n");

  printf("* digite nome: ");
  scanf("%99[^\n]", nome);

  printf("* digite numero: ");
  scanf("%d", &numero);

  printf("*\n");

  printf("* nome digitado: [%s]\n", nome);
  printf("* numero digitado: [%d]\n", numero);

  printf("*\n");

  return 0;
}

Compilation and testing on Linux:

[~/Projects/testes/so]
$cc 397063.c

[~/Projects/testes/so]
$mv a.out 397063

[~/Projects/testes/so]
$./397063 
*
* digite nome: aaa bbb
* digite numero: 123
*
* nome digitado: [aaa bbb]
* numero digitado: [123]
*

[~/Projects/testes/so]
$

1


Would that be ?

int main(void){
  char s[100];
  int numero; 

printf("Entre com o numero:");

scanf("%d", &numero);

printf("Entre com os caracteres:");

scanf(" %99[^\n]", s);

printf("%s", s);

printf("\n %d",numero);

return 0;

}
  • int main() { char s[100]; printf("name n"); printf("3"); scanf(" %[ n]", s); Return 0; } is type so bro, only I don’t know how to display the same value later with scanf

Browser other questions tagged

You are not signed in. Login or sign up in order to post.