Sponsored Content
Top Forums Programming Can someone summarize what exactly this perticular code is doing Post 302741367 by jim mcnamara on Saturday 8th of December 2012 08:34:30 AM
Old 12-08-2012
See the 0 (zero) in the char a[] array? When printf tries to to display a string (the %s format) it stops with a byte that is zero - ascii NUL. That is the very first byte in the array. Nothing prints, because %s says stop at NUL. The strlen() function works the same way - it stops with NUL. So "length" is zero.

printf promotes a[2] from a char to an int, then prints it -- the %d version of printf.
When you deal with a single signed char (one byte) C has standards. One of those standards or rules discusses promoting values. A signed char datatype when used in a context which deals with aritmetic (number) operations gets placed into a register just like as if it were an int datatype. So the %d format specifier on a char produces a number on the tty.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

space in perticular folder in unix

can any one tell me how to know the free space in perticular folder in unix. size in bytes/MB. thanks in adv. spandu (7 Replies)
Discussion started by: spandu
7 Replies

2. UNIX for Advanced & Expert Users

how to know that a perticular process is started!!!

Hi all, I wanted a write a script which will start executing whenever a particular process will starts running in a background. Is there is any way in Unix if a directory contents changed then a signal/Interrupt will generated and by taking status of that interrupt I can execute some scripts.... (11 Replies)
Discussion started by: zing_foru
11 Replies

3. Shell Programming and Scripting

sort and summarize

Hi Guys, I have a file in UNIX with duplicates, I have use sort command as below to delete duplicates based on the KEY positions/columns but now I do not want to "delete" duplicates but summarize by KEY numeric columns. REALLY NEED HELP... URGENT!!! Thanks in advance. sort -k 1.1,1.92... (6 Replies)
Discussion started by: shotronix
6 Replies

4. Shell Programming and Scripting

Summarize the sed script

Hi folks, I have a situation where i have a raw file like cat file_raw 776 713 111 0776713113 317-713-114 235776713115 776713116 336713117 77 6 713 118 0776713119 235776713120 and would like to replace all leading zeros with 235, remove all spaces and dashes, and make all... (3 Replies)
Discussion started by: jerkesler
3 Replies

5. Shell Programming and Scripting

Using SED/AWK to Summarize Log File in 10min Intervals

I have this huge log file on my linux box that gets generated every day. I'm able to extract the information I need; however I really would like it to be broken down every 10mins. Log File Snippet 01:23:45 MARYHADA Maryhadalittle.lamb(): fleece as white as snow 1394 for and everywhere that... (8 Replies)
Discussion started by: ravzter
8 Replies

6. Shell Programming and Scripting

Summarize file with column matching

Guys, Please help me with this code. I have 2GB file to process and shell seems to be the best option. I am a biologist and though I can think of the logic, the commands are beyond me. Any help is greatly appreciated. Please look at the attched file and the requirement will be very clear. I... (6 Replies)
Discussion started by: newbie83
6 Replies

7. Shell Programming and Scripting

Summarize the values from files

One of my process will create a file Market.txt with data like below. Count Markt file 334936 /pdm/data001/P3_Quest_5HT_AMERGE.csv 2770787 /pdm/data001/P3_Quest_ARB_ATACAND.csv 1198143 /pdm/data001/P3_Quest_Bisp_ACTONEL.csv 3821864 /pdm/data001/P3_Quest_CONTRA_ALL_OTHER_CONTRA.csv... (7 Replies)
Discussion started by: katakamvivek
7 Replies

8. IP Networking

Trace route to a perticular port

How can I trace a route from one server to a certain port on another server? (3 Replies)
Discussion started by: sewood
3 Replies

9. Shell Programming and Scripting

Bash cript to calculate summarize address

Hi, I need to write a bash script that when i enter two ip address, it will calculate summerize address for them. Examlpe: 192.168.1.27/25 192.168.1.129/25 Result will be: 192.168.1.0/24 can you help me with this script? I even dont know how to start with it (3 Replies)
Discussion started by: Miron
3 Replies

10. Shell Programming and Scripting

Using awk to Summarize Log File in 5min Intervals

I have huge log file that taken every minute and I need the total at 5min intervals. Sample log: #timestamp(yyyymmddhhmm);result;transaction 201703280000;120;6 201703280001;120;3 201703280002;105;3 201703280003;105;5 201703280004;105;5 201703280005;105;4 201703280006;120;2... (2 Replies)
Discussion started by: wwolfking
2 Replies
ECVT(3) 						   BSD Library Functions Manual 						   ECVT(3)

NAME
ecvt, fcvt, gcvt -- convert double to ASCII string SYNOPSIS
#include <stdlib.h> char * ecvt(double value, int ndigit, int * restrict decpt, int * restrict sign); char * fcvt(double value, int ndigit, int * restrict decpt, int * restrict sign); char * gcvt(double value, int ndigit, char *buf); DESCRIPTION
These functions are provided for compatibility with legacy code. New code should use the snprintf(3) function for improved safety and porta- bility. The ecvt(), fcvt() and gcvt() functions convert the double precision floating-point number value to a NUL-terminated ASCII string. The ecvt() function converts value to a NUL-terminated string of exactly ndigit digits and returns a pointer to that string. The result is padded with zeroes from left to right as needed. There are no leading zeroes unless value itself is 0. The least significant digit is rounded in an implementation-dependent manner. The position of the decimal point relative to the beginning of the string is stored in decpt. A negative value indicates that the decimal point is located to the left of the returned digits (this occurs when there is no whole number component to value). If value is zero, it is unspecified whether the integer pointed to by decpt will be 0 or 1. The decimal point itself is not included in the returned string. If the sign of the result is negative, the integer pointed to by sign is non-zero; otherwise, it is 0. If the converted value is out of range or is not representable, the contents of the returned string are unspecified. The fcvt() function is identical to ecvt() with the exception that ndigit specifies the number of digits after the decimal point (zero-padded as needed). The gcvt() function converts value to a NUL-terminated string similar to the %g printf(3) format specifier and stores the result in buf. It produces ndigit significant digits similar to the %f printf(3) format specifier where possible. If ndigit does allow sufficient precision, the result is stored in exponential notation similar to the %e printf(3) format specifier. If value is less than zero, buf will be prefixed with a minus sign. A decimal point is included in the returned string if value is not a whole number. Unlike the ecvt() and fcvt() func- tions, buf is not zero-padded. RETURN VALUES
The ecvt(), fcvt() and gcvt() functions return a NUL-terminated string representation of value. WARNINGS
The ecvt() and fcvt() functions return a pointer to internal storage space that will be overwritten by subsequent calls to either function. The maximum possible precision of the return value is limited by the precision of a double and may not be the same on all architectures. The snprintf(3) function is preferred over these functions for new code. SEE ALSO
printf(3), strtod(3) STANDARDS
The ecvt(), fcvt() and gcvt() functions conform to IEEE Std 1003.1-2001 (``POSIX.1''). BSD
May 31, 2007 BSD
All times are GMT -4. The time now is 01:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy