Jump to content

Question about arrays/counters

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Sparty2009

Sparty2009

    Newbie

  • Members
  • PipPip
  • 13 posts
I am not sure what I have screwed up, I have a program that I am trying to

For each argument (in order), the program will print on separate lines
1. integer followed by the argument value if the argument is an integer.
2. error followed by the argument value if the argument is none of the above.

something like this:

./a f c 8 7 c
error a
error c
integer 8
integer 7
error c

I have it print integer, but it doesnt work right, I cant get the integer to print after the word integer, and my error is screwed up. Can anyone point me in the direction of my error? I would really appreciate it.

Thanks

#include <stdio.h>

#include "csc1325.h"



int main (int argc, char * argv[])  {

   int i;

   i = 0;

   while (argv[i] != 0)  {

      char * s;

      s = argv[i];

      int k;

      k = 0;

      if (IsInt(argc, argv, i ) == 1)  {

         printf("integer\n", i);

      }

         k = k + 1;

      if (argv[i] == 0)  {

         printf("error\n",  argc);

      }

         k = k + 1;

      i = i + 1;


   }

   return 0;

}


#2
TkTech

TkTech

    The Crazy One

  • Moderators
  • 1,396 posts
Because you aren't printing it anywhere? Because you seem to have tried, here is a complete answer.