Jump to content
Fórum Script Brasil
  • 0

preciso de ajuna na leitura de string


Túlio Cezar

Question

Não consigo fazer o scanf da opção 1 ping ler o espaço do endereço. ex 192.168.1.1 -t

Quando uso scanf("%[^\n]s", ip); da erro.

Se alguém poder ajudar agradeço.

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

int main ()

{
  char  i;
  char p[30] = "ping ";
  char ip[50];
  char resultado[100];
  
  
  do
   {
        system("cls");
        printf("\t\t\t*------------------------*\n");
        printf ("\t\t\t* |\\\\\\ Bem Vindo!!! ///| *\n");
        printf("\t\t\t*------------------------*\n\n\n");
        printf ("\t\t\tEscolha a Opcao a Seguir:\n\n\n");
        printf ("\t\t\t(1)...Ping\n\n");
        printf ("\t\t\t(2)...Netstat\n\n");
        printf ("\t\t\t(3)...Rotas\n\n");
        printf ("\t\t\t(4)...Banco de dados\n\n");
        printf ("\t\t\t(5)...Sair\n\n\n\n");
        scanf("%d", &i); 
    
        switch (i)
       {
     [color="#FF0000"]  [b] case 1:
               printf ("\t\t Digite um endereco ou Ip: ");
              
               scanf("%[^\n]s", ip);
               [color="#FF0000"][/color]
               printf (ip);
               
               //sprintf( resultado, "%s %s", p, ip);
             
               //system (resultado);
               sleep(5000);
               getch();
               fflush(stdin);
               break;
               [/b][/color]
        case 2:
               system ("\t\tnetstat -es\n");
               sleep(10000);
               getch();
        break;
        case 3:
               system ("\t\troute print\n");
               sleep(10000);
               getch();
        break;
        case 4:
              system ("\t\tmysql -u root -p\n");
        break;
        case 5:
               system ("exit");
        break;
       }
     
        
   } while(( i>=1 && i<5) || (i<=0 || i>=6));
     
  
  return 1;
}

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...