so what you mean that 1234 is NOT a hex number ?
you can set a flag to check if it is a hex number and if it is, then move to change cases
so what you mean that 1234 is NOT a hex number ?
you can set a flag to check if it is a hex number and if it is, then move to change cases
Last edited by gaurav9991; 11-24-2010 at 12:41 AM.
Uhh...1234 is also a hexadecimal number...Originally Posted by Sonia
If you understand what you're doing, you're not learning anything.
yeah i cud that... but it shud work fine with the method i have used too. there are errors being generated with that pointer can u pl address that
it will be easy for us to help you if you tell us about errors
please specify what are they
1.generates and error " cannot convert int[4] * to int" and "type mismatch in parameter 1"Code:low_up(&temp);
2.generates a misplaced else error.Code:else printf("this is not a hexadeimal number");
in low_up you are passing an integer pointer(array pointer)Code:#include<stdio.h> #include<conio.h> #include<math.h> void low_up(int); void main() { char ch[4]; int temp[4],i; clrscr(); printf("Enter a hexadecimal number"); for(i=0;i<4;i++) { scanf("%c", &ch[i]); temp[i]=ch[i]; } if((ch[i]>='a' && ch[i]<='f')||(ch[i]>='A' && ch[i]<='F')) { printf("This is a hexadecimal number"); } low_up(&temp); for(i=0;i<4;i++) printf("%d\n", temp[i]); else // where is it's if ? printf("this is not a hexadeimal number"); getch(); } void low_up(int *j) { int k; for(k=0;k<4;k++) { if(*j>=97 && *j<=102) *j=*j - 32; else if(*j>=65 && *j<=70) *j=*j + 32; j++; } for(i=0;i<4;i++) { printf("%c", *j); j++; } }
name of an array itself represents it's base address, so no need to use & while calling
Your whole low_up() function is convoluted and ugly and the bottom loop is wrong. Why not make it a little easier to read?
The problem with the bottom part of your loop is that j has already walked off the end of your array by the end of the first loop, so you're ending up with undefined operations since j is outside the bounds of the array.Code:void low_up(int *j) { int k; for(k = 0;k < 4;++k) j[k] = isupper(j[k]) ? tolower(j[k]) : toupper(j[k]); }
If you understand what you're doing, you're not learning anything.
well see the prob is that if the number does not contain any alphabets i want it to print " it is not a hexadecimal number" and also after the low up function is done i want to print the number... so i don understand where to put that else... i'm confused.,..
and even if i enter &temp instead of temp. it still gives the same error
Last edited by Sonia; 11-24-2010 at 01:52 AM.
here is the code but don't copy as it is! I am posting the complete code just you to understand how flag can be used (assuming you don't know) and the low_up fun is from the upper post. look at the data-type of ch and temp(using int will be lengthy)
Code:#include<stdio.h> #include<conio.h> #include<math.h> void low_up(char *); int main() { char ch[4], temp[4], i, flag; printf("Enter a hexadecimal number : "); for (i = 0; i < 4; i++) { scanf("%c", &ch[i]); temp[i] = ch[i]; } flag = 0; for (i = 0; i < 4; i++) { if ((ch[i] >= 'a' && ch[i] <= 'f') || (ch[i] >= 'A' && ch[i] <= 'F') || (ch[i] >= 1 && ch[i] <= 9)) ; { flag++; } } if (flag == 4) { printf("this is a hexadeimal number"); low_up(ch); printf("\n\n"); } else { printf("this is NOT a hexadeimal number"); } getch(); return 0; } void low_up(char *j) { int k, i; for (k = 0; k < 4; ++k) j[k] = isupper(j[k]) ? tolower(j[k]) : toupper(j[k]); for (i = 0; i < 4; i++) { printf("%c", *j); j = j + 1; } }
@gaurav9991: I'm guessing that's a booby trap in your code.
If you understand what you're doing, you're not learning anything.
Hello. How is the weather? We have had 2" of snow here and a bit too cold to go out, so I decided to look for a program to write.
Is this what you were trying to do?
This is actually C.Code:anch -run ishex.a.c #execute source code! Enter a hex number. Eat 'Eat' is not hex! anch -run ishex.a.c Enter a hex number. FeeD 'FeeD' is hex!
I just forgot a few brackets and stuff to test this free, open-source pseudocode compiler.
Anchor | freshmeat.net converts it to C, compiles it, and even invokes tcc to compile it to memory and run it directly.
Code:#include <stdio.h> #include <string.h> #define MAX_STRING 4 #ifndef stricmp #define stricmp strcasecmp #endif int isHex char *s static int i char u[MAX_STRING+1] if s sscanf(s,"%x",&i) sprintf(u,"%x",i) if !stricmp(s,u) return 1 return 0 int main void char s[MAX_STRING+1] char fmt[10] sprintf fmt,"%%%is",MAX_STRING printf "Enter a hex number.\n" scanf fmt,&s printf "'%s' is %shex!\n",s,isHex(s)?"":"not " return 0
Oh no python fan?
@gaurav...
your code is good and it made clear that flag part... but then i'm not allowed to use isupper or islower. and so for that i need to compare the ascii values for which i need the int array temp[].
@itsme86 i really don understand that if() func part man..
@hellork
i didn even get a single part of ur program...
u guys i'm, jus losing it now... i'm so confused
Last edited by Sonia; 11-24-2010 at 03:20 AM.