Guest User

fgets error, unwanted 0

a guest
Nov 26th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. main.cpp
  2. ____________________________________________________________________________________________________________
  3.  
  4. #include "Client.h"
  5.  
  6. int main () {
  7.  
  8.    
  9.     char cmd[10];
  10.     BOOL ok = true;
  11.  
  12.     while (ok) {
  13.         printf("Command: ");
  14.         scanf("%s",&cmd);
  15.  
  16.         if (strcmp(cmd, "client") == 0 || strcmp(cmd, "Client") == 0)
  17.             RunClient();
  18.         /*else if (strcmp(cmd, "server") == 0 || strcmp(cmd, "Server") == 0)
  19.             RunServer();
  20.         else if (strcmp(cmd, "close") == 0 || strcmp(cmd, "Close") == 0) {
  21.             CloseServer();
  22.             ok = false;
  23.         }*/
  24.         else
  25.             printf("Invalid arguments\r\nUse with arguments client, server or close\r\n");
  26.     }
  27.  
  28.     return 0;
  29. }
  30.  
  31. Client.cpp
  32. ____________________________________________________________________________________________________________
  33.  
  34. #include "Client.h"
  35.  
  36. int ReadInput() {
  37.     char buffer [5];
  38.     printf("Number: ");
  39.     fgets(buffer,5,stdin);
  40.     return atoi(buffer);
  41. }
  42.  
  43. void RunClient() {
  44.     int number;
  45.     int i = 5;
  46.     while (i != 0) {
  47.         number = ReadInput();
  48.         printf("Number is: %d\n",number);
  49.         i--;
  50.     }
  51. }
  52.  
  53. Common.h
  54. ____________________________________________________________________________________________________________
  55.  
  56. #pragma once
  57.  
  58. #define CONNECT_NAMEDPIPE "\\\\.\\pipe\\ClientToServer"
  59.  
  60. #include <stdio.h>
  61. #include <windows.h>
  62.  
  63. struct Msg {
  64.     int value[10];
  65.     int length;
  66. };
  67.  
  68. struct MinMax {
  69.     int min;
  70.     int max;
  71. };
  72.  
  73. Client.h
  74. ____________________________________________________________________________________________________________
  75.  
  76. #include "Common.h"
  77.  
  78. void RunClient();
  79. void CloseServer();
Advertisement
Add Comment
Please, Sign In to add comment