[Solved] Enum and strings

Try the following approach #include <stdio.h> #include <string.h> int main(void) { enum Animal { cat, dog, elephant }; char * animal_name[] = { “cat”, “dog”, “elephant” }; enum Animal b; size_t n; char s[100]; fgets( s , sizeof( s ), stdin ); n = strlen( s ); if ( s[n – 1] == ‘\n’ ) … Read more

[Solved] Button to show previous string

create a new member for your Activity like: int actual = 0; Then create a ‘next’ button: nextButton = (Button) findViewById(…); nextButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { actual = actual < countires.length – 1 ? actual + 1 : actual; String country = countires[actual]; btn1.setText(country); } }); Same goes for the previous … Read more

[Solved] Can I change the datatype of previously declared variable in C?

Since the pointer returned by malloc() is sufficiently well aligned to be used as a pointer to any type, you could (but probably shouldn’t) use: assert(sizeof(float) <= 10); void *data = malloc(10); char *str = data; strcpy(str, “123.4”); float *vp = data; *vp = strtof(str, NULL); …use *vp… free(data); And now you can use *vp … Read more

[Solved] Compare 2 strings in C and print equal part [closed]

Please look if this program can help you. It takes the two strings as arguments from the command line. #include <stdio.h> #include <stdlib.h> #include <string.h> int *substring(char *s, char *t) { int strlen1 = strlen(s); int strlen2 = strlen(t); int len = strlen1 < strlen2 ? strlen1 : strlen2; int i, j, k; int longest … Read more

[Solved] i cant get my calculator to work

Try using input.next(); instead of input.nextLine(); Because input.nextLine(); advances this scanner past the current line and returns the input that was skipped. so if your input was 20, +, and 24, your method calc would get 20,24,null. 2 solved i cant get my calculator to work