Newbie - Urgent help needed. 
Author Message
 Newbie - Urgent help needed.

I am a newbie at this and am a little stuck. Is there someone
out there who can help please.

The problem is this...

If a user inputs four characters (c1,c2,c3,c4)
and c1 and c4 have only two variables... if c1 is m then c4 must
be 0 or if c1 is t then c4 must be 1. And c2 and c3 together are
an integer in the range of 1 - 59. I also have to loop it until
a sentinel like '$$$$' terminates the program.

I can get all the information in and can check certain data but
I can't get all the checks done in the required format.

It has been requested that I should have two functions declared
like

int check23(char c2, char c3);
int check14(char c1, char c4);

I am incredibly frustrated at solving this and feel that some
guidance would assist with the rest of my project. This problem
has been holding me up for two weeks now and the more I try to
resolve it the more backwards I go.

Any help would be appreciated.

Regards
Chris McKay

* Sent from RemarQ http://www.*-*-*.com/ The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Fri, 22 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.


Quote:

>> I am a newbie at this and am a little stuck. Is there someone
>> out there who can help please.

>> The problem is this...

>> If a user inputs four characters (c1,c2,c3,c4)
>> and c1 and c4 have only two variables... if c1 is m then c4
must
>> be 0 or if c1 is t then c4 must be 1. And c2 and c3 together
are
>> an integer in the range of 1 - 59. I also have to loop it
until
>> a sentinel like '$$$$' terminates the program.

>> I can get all the information in and can check certain data
but
>> I can't get all the checks done in the required format.

>> It has been requested that I should have two functions
declared
>> like

>> int check23(char c2, char c3);
>> int check14(char c1, char c4);

>> I am incredibly frustrated at solving this and feel that some
>> guidance would assist with the rest of my project. This
problem
>> has been holding me up for two weeks now and the more I try to
>> resolve it the more backwards I go.

>> Any help would be appreciated.

>> Regards
>> Chris McKay

>> * Sent from RemarQ http://www.remarq.com The Internet's

Discussion Network *
Quote:
>> The fastest and easiest way to search and participate in
Usenet - Free!

>First of all I would point out that thinking about it would be
easier
>for you to learn rather than being spoon-fed, but am in a good
mood
>today.
>Thanks Chris for the advice and help. I might just like to

point out though that while you think you are spoon feeding me,
I actually feel like you are using a shovel! If I didn't need
the help I wouldn't ask and please remember that not all of us
are as quick on the uptake as others.Did you not at some stage
when learning the language have some form of difficulty that you
needed help with?

And yes I am thankful for the help you have given, even though a
couple of the codes used by you are new to me, I shall work
through them.

Cheers
Chris

- Show quoted text -

Quote:
>int check23(char c2, char c3)
>{
>   // something like return 0 for bad and 1 for good:
>   if ((1 <= c2) && (c2 <= 59) && (1 <= c3) && (c3 <= 59))
return 1;
>   return 0;
>}

>or you could just go the easy way:

>int check23(char c2, char c3)
>{
>   // something like return 0 for bad and 1 for good:
>   return !((1 <= c2) && (c2 <= 59) && (1 <= c3) && (c3 <= 59));
>}

>and then for check14

>int check14(char c1, char c4)
>{
>   // again 0 == bad and 1 == good.
>   return !(((c1 == 'm') && (c4 == 0)) || ((c1 == 't') && (c4
== 1))
>}

>your loop would be something like:

>int main()
>{
>   char c1,c2,c3,c4;
>   for (int done = 0; done != 1; )
>   {
>      // Get your 4 characters using an input function
>      // call your checks and then
>      // if check returned 0 then
>      // if c1 == c2 == c3 == c4 == '$' then done = 1;
>      // Note that it is required for you to do the rest
>      // =]
>   }

>   return 0;
>}

>--
>-Chris

>"I don't suffer from Insanity... I enjoy every minute of it!" -
Me
>"I will be happened, it shall be going to be happened, it will
be was an
>event that could will have been taken place in the future.
Simple as
>that!" - Arnold Rimmer (Red Dwarf)
>"You can assign a pointer to a pointer to a function to a
pointer to
>void" - Mike Burrell (comp.lang.c)
>"How many C++ Programmers does it take to change a lightbulb?
None. It's
>a hardware problem." - Anon

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!


Fri, 22 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

Quote:




> >> I am a newbie at this and am a little stuck. Is there someone
> >> out there who can help please.

> >> The problem is this...

> >> If a user inputs four characters (c1,c2,c3,c4)
> >> and c1 and c4 have only two variables... if c1 is m then c4
> must
> >> be 0 or if c1 is t then c4 must be 1. And c2 and c3 together
> are
> >> an integer in the range of 1 - 59. I also have to loop it
> until
> >> a sentinel like '$$$$' terminates the program.

> >> I can get all the information in and can check certain data
> but
> >> I can't get all the checks done in the required format.

> >> It has been requested that I should have two functions
> declared
> >> like

> >> int check23(char c2, char c3);
> >> int check14(char c1, char c4);

> >> I am incredibly frustrated at solving this and feel that some
> >> guidance would assist with the rest of my project. This
> problem
> >> has been holding me up for two weeks now and the more I try to
> >> resolve it the more backwards I go.

Perhaps you should define one function, not two, to valid the stock code.
Something like
int Valid_StockNr(const char *s);

And when you write the function, break up the conditionals some in order to get
a better understanding.

Here is an example, but it probably does more than you need and may confuse you.
If nothing else, look closely at the conditionals.

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

int Valid_StockNr(const char *s) {
   int n;
   char temp[8];

   if(strlen(s) != 4) return 0; /* if it ain't 4 characters it is bad */
   strcpy(temp,s);
   if(temp[0] != 'm') if(temp[0] != 't') return 0; /* First char must be 'm' or
't' */
   if(temp[0] == 'm') {
      if(temp[3] != '0') return 0;
      } /* if first is 'm' then last must be '0' */
   else if(temp[3] != '1') return 0; /* since first is 't', then last must be
'1' */

 /* OK, the first and last characters are ok. Now, convert middle two to int */
 temp[3] = '\0';
 n = atoi(&temp[1]);

 if(n < 1 ||n > 59) return 0; /* test the int conversion for out of range */
 return 1;
 }

int main(void) {
   char *s,input[16];

   for( ; ; ) {  /* endless loop */
     printf("Enter the Stock Code (Enter x to exit): ");
     fflush(stdout);
     fgets(input,sizeof input, stdin);
     if(input[0] == 'x') break;
     if((s = strchr(input,'\n')) != NULL) *s = '\0';
     if(Valid_StockNr(input)) printf("Stock Nr: %s is valid\n\n",input);
     else  puts("Invalid Stock Number. Try again.\n");
     }
   return 0;
   }

--
Al Bowers
Tampa, FL  USA
comp.lang.c faq: http://www.eskimo.com/~scs/C-faq/top.html

http://www.geocities.com/abowers822/



Fri, 22 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

Quote:





>> >> I am a newbie at this and am a little stuck. Is there
someone
>> >> out there who can help please.

>> >> The problem is this...

>> >> If a user inputs four characters (c1,c2,c3,c4)
>> >> and c1 and c4 have only two variables... if c1 is m then c4
>> must
>> >> be 0 or if c1 is t then c4 must be 1. And c2 and c3
together
>> are
>> >> an integer in the range of 1 - 59. I also have to loop it
>> until
>> >> a sentinel like '$$$$' terminates the program.

>> >> I can get all the information in and can check certain data
>> but
>> >> I can't get all the checks done in the required format.

>> >> It has been requested that I should have two functions
>> declared
>> >> like

>> >> int check23(char c2, char c3);
>> >> int check14(char c1, char c4);

>> >> I am incredibly frustrated at solving this and feel that
some
>> >> guidance would assist with the rest of my project. This
>> problem
>> >> has been holding me up for two weeks now and the more I
try to
>> >> resolve it the more backwards I go.

>Perhaps you should define one function, not two, to valid the
stock code.
>Something like
>int Valid_StockNr(const char *s);

>And when you write the function, break up the conditionals some
in order to get
>a better understanding.

>Here is an example, but it probably does more than you need and
may confuse you.
>If nothing else, look closely at the conditionals.

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

>int Valid_StockNr(const char *s) {
>   int n;
>   char temp[8];

>   if(strlen(s) != 4) return 0; /* if it ain't 4 characters it
is bad */
>   strcpy(temp,s);
>   if(temp[0] != 'm') if(temp[0] != 't') return 0; /* First
char must be 'm' or
>'t' */
>   if(temp[0] == 'm') {
>      if(temp[3] != '0') return 0;
>      } /* if first is 'm' then last must be '0' */
>   else if(temp[3] != '1') return 0; /* since first is 't',
then last must be
>'1' */

> /* OK, the first and last characters are ok. Now, convert

middle two to int */

- Show quoted text -

Quote:
> temp[3] = '\0';
> n = atoi(&temp[1]);

> if(n < 1 ||n > 59) return 0; /* test the int conversion for
out of range */
> return 1;
> }

>int main(void) {
>   char *s,input[16];

>   for( ; ; ) {  /* endless loop */
>     printf("Enter the Stock Code (Enter x to exit): ");
>     fflush(stdout);
>     fgets(input,sizeof input, stdin);
>     if(input[0] == 'x') break;
>     if((s = strchr(input,'\n')) != NULL) *s = '\0';
>     if(Valid_StockNr(input)) printf("Stock Nr: %s is
valid\n\n",input);
>     else  puts("Invalid Stock Number. Try again.\n");
>     }
>   return 0;
>   }

>--
>Al Bowers
>Tampa, FL  USA
>comp.lang.c faq: http://www.eskimo.com/~scs/C-faq/top.html

>http://www.geocities.com/abowers822/

Thanks Al for your help as well. Now that I have three variances
I find myself even more confused.

I have run out of time for the assignment now so will have to
skip it and start thinking about the next one. Thanks everybody
for your help.
Chris

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Fri, 22 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

Quote:

> > int main()
> > {
> >    char c1,c2,c3,c4;
> >    for (int done = 0; done != 1; )

> One moderate question:
> Where did you get your C99 compiler from?

It aint a C99  compiler. Its a C++ Compiler.  And sorry if Im wrong
about anything but I tend to be half asleep. The fire algorithm wont
behave!  =]

--
-Chris

"I don't suffer from Insanity... I enjoy every minute of it!" - Me
"I will be happened, it shall be going to be happened, it will be was an
event that could will have been taken place in the future. Simple as
that!" - Arnold Rimmer (Red Dwarf)
"You can assign a pointer to a pointer to a function to a pointer to
void" - Mike Burrell (comp.lang.c)
"How many C++ Programmers does it take to change a lightbulb? None. It's
a hardware problem." - Anon



Sat, 23 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

Quote:

> > > int main()
> > > {
> > >    char c1,c2,c3,c4;
> > >    for (int done = 0; done != 1; )

> > One moderate question:
> > Where did you get your C99 compiler from?

> It aint a C99  compiler. Its a C++ Compiler.

Then you'd better be very careful about compiling C code with it; not
all perfectly good C code is compilable by a C++ compiler, and not all
code that a C++ compiler will accept is valid C, even if it looks like
it is; as witness the above bit. So please don't confuse the newbies by
making it look as if your C++ is actually C.

Richard



Sat, 23 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

Quote:



>> > > int main()
>> > > {
>> > >    char c1,c2,c3,c4;
>> > >    for (int done = 0; done != 1; )

>> > One moderate question:
>> > Where did you get your C99 compiler from?

>> It aint a C99  compiler. Its a C++ Compiler.

>Then you'd better be very careful about compiling C code with
it; not
>all perfectly good C code is compilable by a C++ compiler, and
not all
>code that a C++ compiler will accept is valid C, even if it
looks like
>it is; as witness the above bit. So please don't confuse the
newbies by
>making it look as if your C++ is actually C.

>Richard

Hi guys, me again.

I might have missed the deadline for my assignment but that
doesn't mean that I am about to give up on this. I have so far
got to the stage as coded below which checks the input and
validates it correctly, however there are a number of errors in
the code that needs correcting and this is where I am looking
for you guys to help me out.  The errors I get when running the
program are:

The program does not terminate when I input the data $$$$, which
is what I want it to do.

The program will validate a stock code of eg E001 when the
minimum 00 should be is 01.

The program will accept and validate any number of characters
and will validate it if the firt 4 meet the criteria.

I need to be able to convert the c1 character to uppercase if it
is input as lowercase. I tried this but had no success. This
would tidy up the large line of code when doing the check.

I think that is about it.

Once again, any help is graciously accepted and as you can see,
I have learnt a little. By the way, the reason it is written
like this is we are not allowed to use any code, headers etc.,.
that we have not learnt thus far. Most of what we have learnt is
in here.

regards
Chris McKay

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sat, 23 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

Quote:



>> > > int main()
>> > > {
>> > >    char c1,c2,c3,c4;
>> > >    for (int done = 0; done != 1; )

>> > One moderate question:
>> > Where did you get your C99 compiler from?

>> It aint a C99  compiler. Its a C++ Compiler.

>Then you'd better be very careful about compiling C code with
it; not
>all perfectly good C code is compilable by a C++ compiler, and
not all
>code that a C++ compiler will accept is valid C, even if it
looks like
>it is; as witness the above bit. So please don't confuse the
newbies by
>making it look as if your C++ is actually C.

>Richard

Not sure what happened to my last posting so here goes again.

As you can see I might have missed my assignment deadline but I
am going to get this right if it kills me, after all that is
what I am doing the paper for, TOO LEARN.

The code below is what I have written thus far and while it
works, to a point, there is still some help that I need.
The program validates the right code but the few problems that I
need help with are as follows.

1. The $$$$ sentinel that is meant to terminate the program does
not work.

2. The program will accept any number of characters as input and
will return a valid code if the first 4 meet the criteria as
set. This should not happen. How do I get around this?

3. The program will give a valid return to a stock code that has
00 as the second and third characters but it should return not
valid as the stock codes must have the second and third digit
combined to return an integer between 1 and 59. Any toughts?

4. The validation code I have used is not neat enough when it
comes to checking c1. I need to convert the c1 input to
uppercase if entered a lowercase. This would tidy it up.
Unfortunately I have tried to do this but can't get the right
results. Help please.

Apart from that I think all else is relatively ok albeit a
rather untidy, but I shall learn.

To all, thanks for the help thus far, your help has made me
learn a thing or two, after all, it was only yesterday I
couldn't get past accepting the input characters.

All help graciously accepted.

Chris McKay

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sat, 23 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

Quote:



>> > > int main()
>> > > {
>> > >    char c1,c2,c3,c4;
>> > >    for (int done = 0; done != 1; )

>> > One moderate question:
>> > Where did you get your C99 compiler from?

>> It aint a C99  compiler. Its a C++ Compiler.

>Then you'd better be very careful about compiling C code with
it; not
>all perfectly good C code is compilable by a C++ compiler, and
not all
>code that a C++ compiler will accept is valid C, even if it
looks like
>it is; as witness the above bit. So please don't confuse the
newbies by
>making it look as if your C++ is actually C.

>Richard

It is not my night for posting so here goes version three:

Not sure what happened to my last posting so here goes again.

As you can see I might have missed my assignment deadline but I
am going to get this right if it kills me, after all that is
what I am doing the paper for, TOO LEARN.

The code below is what I have written thus far and while it
works, to a point, there is still some help that I need.
The program validates the right code but the few problems that I
need help with are as follows.

1. The $$$$ sentinel that is meant to terminate the program does
not work.

2. The program will accept any number of characters as input and
will return a valid code if the first 4 meet the criteria as
set. This should not happen. How do I get around this?

3. The program will give a valid return to a stock code that has
00 as the second and third characters but it should return not
valid as the stock codes must have the second and third digit
combined to return an integer between 1 and 59. Any toughts?

4. The validation code I have used is not neat enough when it
comes to checking c1. I need to convert the c1 input to
uppercase if entered a lowercase. This would tidy it up.
Unfortunately I have tried to do this but can't get the right
results. Help please.

Apart from that I think all else is relatively ok albeit a
rather untidy, but I shall learn.

To all, thanks for the help thus far, your help has made me
learn a thing or two, after all, it was only yesterday I
couldn't get past accepting the input characters.

All help graciously accepted.

Chris McKay

The code:

int main( void )
{
        char c1,c2,c3,c4;
        int test1, test2, end;

        do
{
                         /* input four digits */
        printf("Enter a four character part number or $$$$ to
exit\n\n");
        scanf(" %c%c%c%c",&c1,&c2,&c3,&c4);
        end = 0;

        if(c1 == c2 == c3 == c4 == '$')  /*$$$$ input while loop
finish*/
        end = 1;
        else
        test1 = check14(c1,c4);     /* funtion call to test
first and last digits */
        test2 = check23(c2,c3);    /* function call to test
middle digits */

{
        printf("This stock code %s valid.\n\n\n",
        test1 && test2 ? "is" : "is not");

Quote:
}
}

        while (end != 1);  /* loop until $$$$ input */

        return 0;

Quote:
}

        int check23(char c2,char c3)
{
        int answer,x,y;

        x = c2 -'0';         /* convert to int for evaluation */
        y = c3 -'0';
                      /* evaluate */
        if ((x <= 5) && (y <= 9))
        answer = 1;
        else answer = 0;
        return answer;       /* return 1 to function if
statement true */

Quote:
}

        int check14(char c1,char c4)
{
        int answer;

        if ((c1 =='M' && c4 == '0') || (c1 == 'm' && c4 == '0')
|| (c1 == 'T' && c4 == '1')
        || (c1 == 't' && c4 == '1') || (c1 == 'E' && c4 == '1')
|| (c1 == 'e' && c4 == '1'))
        answer = 1;
        else answer = 0;

        return answer;  /* return 1 to function if statement
true*/

Quote:
}

int main( void )
{
        char c1,c2,c3,c4;
        int test1, test2, end;

        do
{
                         /* input four digits */
        printf("Enter a four character part number or $$$$ to
exit\n\n");
        scanf(" %c%c%c%c",&c1,&c2,&c3,&c4);
        end = 0;

        if(c1 == c2 == c3 == c4 == '$')  /*$$$$ input while loop
finish*/
        end = 1;
        else
        test1 = check14(c1,c4);     /* funtion call to test
first and last digits */
        test2 = check23(c2,c3);    /* function call to test
middle digits */

{
        printf("This stock code %s valid.\n\n\n",
        test1 && test2 ? "is" : "is not");

Quote:
}
}

        while (end != 1);  /* loop until $$$$ input */

        return 0;

Quote:
}

        int check23(char c2,char c3)
{
        int answer,x,y;

        x = c2 -'0';         /* convert to int for evaluation */
        y = c3 -'0';
                      /* evaluate */
        if ((x <= 5) && (y <= 9))
        answer = 1;
        else answer = 0;
        return answer;       /* return 1 to function if
statement true */

Quote:
}

        int check14(char c1,char c4)
{
        int answer;

        if ((c1 =='M' && c4 == '0') || (c1 == 'm' && c4 == '0')
|| (c1 == 'T' && c4 == '1')
        || (c1 == 't' && c4 == '1') || (c1 == 'E' && c4 == '1')
|| (c1 == 'e' && c4 == '1'))
        answer = 1;
        else answer = 0;

        return answer;  /* return 1 to function if statement
true*/

Quote:
}

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!


Sat, 23 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

 >         if(c1 == c2 == c3 == c4 == '$')  /*$$$$ input while loop
 > finish*/

This line does not do what you think it does.  The operator takes two
operands and returns a single integer with value 0 or 1.  So first
the first operator is evaluated, this returns 1 if the operands are
equal (which I will assume), next that value (1) is compared with c3.
To do what you want you have to compare each variable with '$' and
chain the comparisons with '&&' as you did elsewhere.
--
dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn  amsterdam, nederland; http://www.cwi.nl/~dik/



Sat, 23 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

Quote:

> 1. The $$$$ sentinel that is meant to terminate the program does
> not work.

No wonder; see Dik's post.

Quote:
> 2. The program will accept any number of characters as input and
> will return a valid code if the first 4 meet the criteria as
> set. This should not happen. How do I get around this?

Not, using ISO C, unless you mean that the user may enter as much as he
likes, but the program complains when more than four characters are
entered. You cannot constrain the length of actual typed text in ISO C
(though your compiler probably has an extension that can); consider that
C must be able to run on, say, a dumb line-oriented terminal.

Quote:
> 3. The program will give a valid return to a stock code that has
> 00 as the second and third characters but it should return not
> valid as the stock codes must have the second and third digit
> combined to return an integer between 1 and 59. Any toughts?

Yes; see below

Quote:
> 4. The validation code I have used is not neat enough when it
> comes to checking c1. I need to convert the c1 input to
> uppercase if entered a lowercase. This would tidy it up.
> Unfortunately I have tried to do this but can't get the right
> results. Help please.

Ditto.

Quote:
> The code:

(I've taken the liberty of aligning your code a bit.)

You are using some functions from the standard library, amongst which
are variadic functions (printf()/scanf()). You _must_ include the
appropriate headers:

#include <stdio.h>

Quote:
> int main( void )
> {
>   char c1,c2,c3,c4;
>   int test1, test2, end;

>   do {
>                      /* input four digits */
>     printf("Enter a four character part number or $$$$ to exit\n\n");
>     scanf(" %c%c%c%c",&c1,&c2,&c3,&c4);

If you replace c1...c4 with
  char c[6]; // Four chars, \n, '\0'
above and don't use scanf() here but
    fgets(c, sizeof(c), stdin);
you can make your life a bit easier. To begin with, fgets() is less
error-prone than scanf(). Secondly, you can now do the following...

Quote:
>     end = 0;

>     if(c1 == c2 == c3 == c4 == '$')  /*$$$$ input while loop finish*/
>       end = 1;

...because fgets() leaves the newline in the input string, thus allowing
you to check whether the user actually entered only four characters:

      elseif (c[4]!='\n') {
        puts("This code is too long to be valid");
        /* Flush stdin: */
        while (c[strlen(c)-1]!='\n') fgets(c, sizeof(c), stdin);
      }

Quote:
>     else

That brace below should go here.

(This line is marked ***; see below.)

Quote:
>       test1 = check14(c1,c4);    /* funtion call to test first and last digits */
>       test2 = check23(c2,c3);    /* function call to test middle digits */

You should, of course, now check14(c[1], c[4]) etc., but that's a
trivial change.

Quote:
>     {

(This brace should go there^.)

Quote:
>       printf("This stock code %s valid.\n\n\n", test1 && test2 ? "is" : "is not");
>     }
>   } while (end != 1);  /* loop until $$$$ input */

>   return 0;
> }

> int check23(char c2,char c3)
> {
>         int answer,x,y;

>         x = c2 -'0';         /* convert to int for evaluation */
>         y = c3 -'0';
>                       /* evaluate */
>         if ((x <= 5) && (y <= 9))
>         answer = 1;
>         else answer = 0;
>         return answer;       /* return 1 to function if statement true */
> }

IMO there's no reason for all these extra vars and extra calculations.
You can just
int check23(char c2, char c3)
{
  /* Check that <c2><c3> is a two-digit sequence between 01 and 59. */
  return c2>='0' && c2<='5' && c3>='0' && c3<='9' && (c2>'0' || c3>'0');

Quote:
}
> int check14(char c1,char c4)
> {
>   int answer;

>   if ((c1 == 'M' && c4 == '0') || (c1 == 'm' && c4 == '0')
>    || (c1 == 'T' && c4 == '1') || (c1 == 't' && c4 == '1')
>    || (c1 == 'E' && c4 == '1') || (c1 == 'e' && c4 == '1'))
>         answer = 1;
>   else answer = 0;

>   return answer;  /* return 1 to function if statement true*/
> }

Ok. If you want to change c1 inside this function, you need to pass a
pointer to it rather than its value. I think, however, that it would be
easier to just insert

      c[1]=toupper((unsigned char)c[1]);

above, just before you check it, at the line marked ***. That also
simplifies this function, because you can drop the lowercase cases:

int check14(char c1, char c4)
{
  return (c1=='M' && c4=='0') ||
         (c1=='T' && c4=='1') ||
         (c1=='E' && c4=='1');

Quote:
}

[ snip repeated code - it really wasn't your night, was it ;-)? ]

Richard



Sat, 23 Nov 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

...[other good comments snipped]

Quote:
> > 2. The program will accept any number of characters as input and
> > will return a valid code if the first 4 meet the criteria as
> > set. This should not happen. How do I get around this?

> Not, using ISO C, unless you mean that the user may enter as much as he
> likes, but the program complains when more than four characters are
> entered. You cannot constrain the length of actual typed text in ISO C
> (though your compiler probably has an extension that can); consider that
> C must be able to run on, say, a dumb line-oriented terminal.

It took me two tries to parse those negatives correctly.  To make sure
it's clear:  using Standard C I/O facilities you cannot prevent entry of
more than 4 characters on a line, but you can detect it and complain
(and if appropriate demand corrected input) after it has happened.

...

Quote:
> If you replace c1...c4 with
>   char c[6]; // Four chars, \n, '\0'
> above and don't use scanf() here but
>     fgets(c, sizeof(c), stdin);
> [check for line too long]...

Yes.  I agree this is better.  But:
Quote:
> >       test1 = check14(c1,c4);    /* funtion call to test first and last
digits */
> >       test2 = check23(c2,c3);    /* function call to test middle digits
*/

> You should, of course, now check14(c[1], c[4]) etc., but that's a
> trivial change.

Small correction:  the former c1 is now c[0] (not 1) etc.

--
- David.Thompson 1 now at worldnet.att.net



Thu, 05 Dec 2002 03:00:00 GMT  
 Newbie - Urgent help needed.

Quote:

> > You should, of course, now check14(c[1], c[4]) etc., but that's a
> > trivial change.

> Small correction:  the former c1 is now c[0] (not 1) etc.

It must be Tisdale getting to my mind. I think they shoot horses in
cases like these.

Richard



Fri, 06 Dec 2002 03:00:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Newbie needs urgent help, simple question

2. Stupid newbie needs urgent help =)

3. URGENT! Newbie need help on graphics

4. URGENT URGENT dlopen() help needed...

5. Urgent Help Needed-Calling the help file.

6. URGENT ! HELP NEWBIE plz - easy dialog question

7. Help C newbie need help please

8. Help C newbie need help please

9. HELP -- NEWBIE NEEDS HELP

10. Urgent Need help

11. Need Urgent Help::::: Printer

12. Urgent Help needed!

 

 
Powered by phpBB® Forum Software