printf

Why does my code keep printing twice? I don't understand the problem [duplicate]

流过昼夜 提交于 2021-01-28 20:38:54
问题 This question already has answers here : How do you allow spaces to be entered using scanf? (11 answers) Closed last year . #include <stdio.h> #define MAX_STRING_LENGTH 1024 int main(){ char input_name_string[MAX_STRING_LENGTH+1],motive_string[MAX_STRING_LENGTH+1]; printf("What is your name?\n"); scanf("%1024s",input_name_string); printf("your name is %s \n", input_name_string); printf("What is your motive?\n"); scanf(" %1024s",motive_string); printf("your motive is %s \n", motive_string);

x86 Assembly - printf doesn't print without “\n”

好久不见. 提交于 2021-01-28 07:31:08
问题 So I'm confused. I'm going through the book "Programming from the Ground Up" and am working with using libraries. printf is working just fine so long as I include a "\n" in the string, but without it it will print absolutely nothing. Any idea why this happens? Code: .section .data my_str: .ascii "Jimmy Joe is %d years old!\n\0" my_num: .long 76 .section .text .globl _start _start: pushl my_num pushl $my_str call printf movl $1, %eax movl $0, %ebx int $0x80 Also, when I use -m elf_i386 for 32

awk convert ASCII to integer in context of awk command

妖精的绣舞 提交于 2021-01-28 06:08:56
问题 I want to do some manipulation on a file with values coded by ASCII symbols. I have a test file that looks something like this: a> b! I would like to use an awk script to to convert them to integer values and then do further manipulation. I've looked and found a method of converting ASCII to integer: for(n=0;n<256;n++)chr[n]=sprintf("%c",n) but I don't know how to pass my integer values from this array to another array wherein I want to do my numeric manipulation. Example output would be: 195

Printf function who returning an array of int

心不动则不痛 提交于 2021-01-28 05:34:09
问题 I'm trying this exercice but I don't know how to printf my function in main. Exercice: 1) Write a function who returning an int tab with all values between min and max #include <stdlib.h> #include <stdio.h> int *ft_range(int min, int max) { int len; int *tab; len = min; while (len < max) len++; tab = (int *)malloc(sizeof(*tab) * len + 1); while (min < max) { *tab = min; min++; } return(tab); } int main() { ft_range(0, 10); return(0); } 回答1: returning an int tab with all values between min and

Regexp exact word match

霸气de小男生 提交于 2021-01-28 04:32:09
问题 I need to match words from lines. For example: The blue bird is dancing. Yellow card is drawn The day is perfect rainy blue bird is eating The four lines are in a text file l2 . I want to match the blue bird, yellow card, day and every time a line is printed that matched word is printed before the line. y=regexp(l2,('^(?=.*blue bird)|(?=.*day)|(?=.*Yellow card)$')); Is this how it works? I can't get the result. sprintf('[%s]',y,l2); 回答1: MATLAB's regex engine doesn't use \b as word boundary

Keep text in place regardless output bash printf

ぐ巨炮叔叔 提交于 2021-01-27 19:34:01
问题 This happens when numbers gets bigger...Just started with this mess. Text being pushed around by bigger outputs...how do I contain this mess? Accounts......: 5 Mail..........: 7 Banned........: 0 Pets..........: 1 Online........: 0 Tickets.......: 0 Guilds........: 1 Corpses.......: 0 PvP.......: 0 Members.......: 1 Characters....: 10 Gifts.....: 4 <-----HOWTO Reserve/Preserve spaces ?? ?? Should look like this: Accounts......: 5 Mail..........: 7 Banned........: 0 Pets..........: 1 Online...

msvcrt alternative for MinGW? (e.g. to get conforming snprintf)

南笙酒味 提交于 2021-01-27 12:52:47
问题 So here's a fun one... we have a few C libraries which should be platform independent, even though they were developed on linux, because they only rely on the c standard library as defined in ISO/IEC 9899:1999. When we compiled those libraries with MinGW everything seemed to work fine at first, but today we found out that the snprintf() implementation of msvcrt is braindea... sorry, i meant " incompatible " with the definition in the C99 standard. I would have expected a warning from MinGW,

Aligning Output Values in C

人盡茶涼 提交于 2021-01-21 10:12:35
问题 So I'm working on a program which needs to format output. The output is supposed to be aligned, and it does do so with small numbers: But then when I give big numbers, it no longer works: My code is really but here's the part that prints the main output: /* The following code prints out the data */ printf("\n\nStatistics: \n\n"); printf("Descrip\t\tNumber:\t\tTotal:\t\tAverage:\n\n"); printf("Normal\t\t%d\t\t%d\t\t%d\n\n",normal_counter,normal_total,normal_average); printf("Short\t\t%d\t\t%d

Aligning Output Values in C

走远了吗. 提交于 2021-01-21 10:11:13
问题 So I'm working on a program which needs to format output. The output is supposed to be aligned, and it does do so with small numbers: But then when I give big numbers, it no longer works: My code is really but here's the part that prints the main output: /* The following code prints out the data */ printf("\n\nStatistics: \n\n"); printf("Descrip\t\tNumber:\t\tTotal:\t\tAverage:\n\n"); printf("Normal\t\t%d\t\t%d\t\t%d\n\n",normal_counter,normal_total,normal_average); printf("Short\t\t%d\t\t%d

Why is a number sign-extended when it is cast to an unsigned type?

微笑、不失礼 提交于 2020-12-26 07:16:45
问题 I was studying how C stores data in memory by bit patterns. However I have confronted some issues when it comes to printf formatting. I have saved a variable as -10 (I do understand two's complement) and another variable as 246 . Those two variables have bit patterns of 11110110 (which is 0xF6 ). I was trying to print out a value using the unsigned int hexadecimal format in printf . char a = -10; unsigned char b = 246; printf("a : %x , b : %x\n" , (unsigned int) a, (unsigned int) b); //a :