src/main.c
changeset 6 7eb12be31bb5
parent 0 586472add385
child 8 3152de03758e
--- a/src/main.c
+++ b/src/main.c
@@ -40,7 +40,7 @@
 int main (int argc, char **argv)
 {
     UC uc;
-    MSG message;
+    MSG message = { NULL, 0, 0, 0, 0, 0, 0 };
     char buf[513];
     char *msg;
     char *command;
@@ -75,7 +75,7 @@
     if (!(message.stream = irc_connect (uc.server, uc.port)))
         return EXIT_FAILURE;
 
-    if ((len = irc_login (message.stream, uc.nick, uc.pass)) != 0) {
+    if ((len = irc_login (message.stream, uc.server, uc.nick, uc.pass)) != 0) {
         switch (len) {
         case IRC_GENERAL_ERROR:
             printf ("GENERAL ERROR\n");
@@ -97,11 +97,10 @@
             fprintf (message.stream, "TOPIC %s :%s\r\n", uc.channel, uc.topic);
     }
 
-    while (active) {
-        if (fgets (buf, 512, message.stream) == NULL) {
-            active = 0;
-            break;
-        }
+    while (!feof (message.stream)) {
+        message.line = NULL;
+        *buf = 0;
+        fgets (buf, 512, message.stream);
 
         if ((command = irc_parsemessage (buf, &message))) {
             printf ("%10s %s %s\n", command, message.channel, message.line);
@@ -111,7 +110,6 @@
                 printf ("%10s %s", "WRITE", msg);
             }
         }
-        *buf = 0;
     }
     printf ("\n\nClosing Connection\n\n");
     fclose (message.stream);