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 2 years ago.
Improve this question
How to convert number/string into hexadecimal? For instance,
Input a word: My name is Laura
Hexadecimal output:...
Supposing that you have a word already stored in a char array, you could do
#include <string.h>
void print_in_hex(const char *string) {
size_t len;
len=strlen(string);
for (size_t k=0; k<len; k++) {
printf("%02x ", string[k]);
}
printf("\n");
}
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 3 years ago.
Improve this question
copy all characters from one character array to another without using strcpy function.
char s1[80],s2[80];
int i;
printf("input s2");
scanf("%s",&s2);
for(i=0;i<=strlen(s2);i++)
s1[i]=s2[i];
printf("s1:%s",s1);
Instead of scanf, using gets function for getting input with spaces.
#include<stdio.h>
int main()
{
char s1[80],s2[80];
int i;
printf("input s2");
// scanf("%c",&s2);
gets(s2);
printf("%d",strlen(s2));
for(i=0;i<strlen(s2);i++)
{
s1[i]=s2[i];
}
printf("s1:%s",s1);
}
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
i am making a program in C where i ask the user 10 questions and i have a list of 20 questions. I want the machine to randomly pick and ask any 10 questions. Can anyone help me how to do that?
As an outline:
struct Q {
char *q;
int hasbeenselected;
} q[20];
int n;
//
// fill q with your questions and set hasbeenselected to 0;
srand(time(NULL));
for (int i=0; i<10; i++) {
do {
n= rand()%20;
} while (q[n].hasbeenselected==1);
// now ask question q[n].q
q[n].hasbeenselected= 1;
}
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 4 years ago.
Improve this question
#include <stdio.h>
#define number 0
main()
{
int i;
for (i = 0; i < 5; i++)
{
number++;
}
printf("Number is: %d", number);
}
No, 0 is substitued for number by the preprocessor before the compiler gets to work.
The compiler issues a diagnostic when it sees 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 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 8 years ago.
Improve this question
Following is the code to obtain matrix like 11 12 13 etc... I am not getting desired results since long. Help me with the solution.
#include<stdio.h>
int main() {
int i,j;
for(i=1;i<5;i++){
for(j=1;j<5;j++){
printf("%d %d",i,j);
}
printf("\n");
}
fgetc(stdin);
}
Probably because you have a space between the digits:
printf("%d %d",i,j);
Shouldn't it be:
printf("%d%d ",i,j);
for your desired output?
Shouldn't printf("%d %d",i,j); actually be printf("%d%d ",i,j);?