Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
i wanna declare this array in c:
{
{{'7','P','Q','R','S'},{'8','T','U','V'},{'9','W','X','Y','Z'},{'÷'}},
{{'4','G','H','I'},{'5','J','K','L'},{'6','M','N','O'},{'×'}},
{{'1','.','?',',','!'},{'2','A','B','C'},{'3','D','E','F'},{'-'}},
{{'*'},{'0',' '},{'='},{'+'}}
}
how can I do this?
Like this
const wchar_t* array[4][4] = {
{L"7PQRS", L"8TUV", L"9WXYZ", L"÷"},
{L"4GHI", L"5JKL", L"6MNO", L"×"},
{L"1.?,!", L"2ABC", L"3DEF", L"-"},
{L"*", L"0" ", L"=", L"+"}
};
I'm using wide characters because of the funky characters you have but YMMV.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I have some materials showing this code. what does code means by making these assignments?
char inputfilename[128];
inputfilename[0] = 0;
char *argv[128];
*argv[1] = 0;
In C, character arrays are terminated by a null character (value 0). In both cases in your example, the code initializes the strings to "empty" (with a terminator in the first element). This would prove useful in any subsequent string operations (strcat, strcpy, etc.).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Can I make a float number in a C program always round up
You can use the ceil() function. For example:
#include <stdio.h>
#include <math.h>
int main () {
float val1 = 1.6;
printf ("Round up to %.1lf\n", ceil(val1));
return(0);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I just started programming and have a question. I have a example input from command line: "number:10" which is "number:" followed by a number. I want to check if the character after "number:" is a number:
int main(int argc, char **argv)
{
if(isdigit(*argv[2]+7)){
printf("correct");
}
return 0;
}
It doesn't work. How can I read only the number in the input string?
*argv[2] is 'n'. *(argv[2]+7) is correct
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
mid= n / 2;//(where n is 10)
int left[sizeof(mid)];
but compiler allocate space for 4[0,1,2,3] elements, it suppose to allocate for 5[0,1,2,3,4] elements.
what could be the issue?
sizeof mean: the size in memory. int is 4 bytes in memory. so sizeof(int)=4.
You probably want to write int left[mid];
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
char string[]="DGS021J0W0S1000.0S20000S3000.0S4000.0S50.00S60.00F";
how to get S[1-5]
thanks!
Use strncpy() standard function
char S[6] = {0};
strncpy(S, string+1 , 5);
If you want to copy from the beginning of the string to the 5th charachter, then your question should be
how to get S[0-4]
and not S[1-5] because array index in C start from 0 and not from 1. and the solution for this case will be
char S[6] = {0};
strncpy(S, string , 5);
I think you are looking for substring methods.
You can do it in two for loops in C.