473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Question dealing with Array print commands

Need another small advice about following:

Could someone explain me what will happen if we have an Array of chars named str and this array doesn't contain the blank character (‘\0’) and try to execute the command: printf("%s", str); Can someone give an explanation please ?

Thanks in advance.....
Oct 29 '09 #1
2 1346
donbock
2,426 Expert 2GB
First of all, character '\0' is called the null character.

By definition, a string is terminated by a null character. If you don't have the null terminator then you don't have a string. The "%s" format code is only for use with strings; otherwise you get undefined behavior.

Undefined behavior is just that -- undefined. Anything can happen. There is no use trying to characterize the undefined behavior. It can change with the phase of the moon.
Oct 29 '09 #2
whodgson
542 512MB
First read again donbock`s post and then consider the following:
%s means Print the null terminated string pointed to by data.
Expand|Select|Wrap|Line Numbers
  1. char *state ="Michigan";
  2. double temp =27.9;
  3. printf("The %s temperature is %5.4f.\n",state,temp);
Prints: The Michigan temperature is 27.9000.
Oct 30 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: 2mc | last post by:
Generally speaking, if one had a list (from regular Python) and an array (from Numerical Python) that contained the same number of elements, would a While loop or a For loop process them at the...
5
by: Michael | last post by:
In the past I have developed many micro-controller products using assembler. I have recently started using C, and so far I love it! I am very motivated to learn and become accustomed to the...
5
by: Keith | last post by:
Good Morning, I am new to .Net so forgive me if this is question is kind of out there. Is there a way to consolidate multiple Dim statements for Sql Commands? I have a page that has around 50 Dim...
10
by: Michael | last post by:
Hi, I'm trying to get my head around the relationship between pointers and arrays. If I have the following: int even = {2,4,6,8,10}; int *evenPtr = {even+4, even+3, even+2, even+1, even};...
17
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not...
3
by: Ara Kooser | last post by:
Hello all, I hope I am posting this correctly. I am running Python 2.4.2 on Slackware 11.0 using IDLE. I am in the process of learning python so I am writing a text adventure game using...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
4
by: cjl | last post by:
As a learning exercise, I am trying to write a web-based version of 'drawbot' in PHP. See: http://just.letterror.com/ltrwiki/DrawBot I am interested in hearing ideas about how to approach...
2
by: ar30067 | last post by:
The 36 possible outcomes of rolling two dice. 7.18 What does the following program do? 1 // Ex. 7.18: Ex07_18.cpp 2 // What does this program do? 3 #include <iostream>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.