Hi,
Is there a function in C that computes the number of characters in a
string.
I want to be able to compute the number of chars in the string '1 3 4
5' by suppressing the ' ', so length should be 4 instead of 7...
Thanx
Sam 6 3323
berthelot samuel wrote: Is there a function in C that computes the number of characters in a string.
Yes, it's strlen(). Don't forget #include <string.h>.
I want to be able to compute the number of chars in the string '1 3 4 5' by suppressing the ' ', so length should be 4 instead of 7...
What is the exact text of the problem you have to solve for your course?
My guess is that you are taking the wrong approach.
Best regards,
Sidney
"Sidney Cadot" <si****@jigsaw. nl> schrieb im Newsbeitrag
news:bp******** **@news.tudelft .nl... berthelot samuel wrote:
Is there a function in C that computes the number of characters in a string.
Yes, it's strlen(). Don't forget #include <string.h>.
I want to be able to compute the number of chars in the string '1 3 4 5' by suppressing the ' ', so length should be 4 instead of 7...
What is the exact text of the problem you have to solve for your course? My guess is that you are taking the wrong approach.
Can it be, that the OP has wide char strings?
In this case wcslen() is what he/she needs
Just a wild guess
Robert sa************* *@voila.fr (berthelot samuel) wrote: Hi, Is there a function in C that computes the number of characters in a string. I want to be able to compute the number of chars in the string '1 3 4 5' by suppressing the ' ', so length should be 4 instead of 7...
There's no such standard function, but it's easy to write one
yourself. Just lookup the various is...() functions declared
in ctype.h and do something like:
#include <ctype.h>
int strGraphCount( const char *s )
{
int res = 0;
for( ; *s; ++s )
if ( isgraph( *s ) )
++res;
return res;
}
HTH
Regards
--
Irrwahn
(ir*******@free net.de)
Robert Stankowic wrote: "Sidney Cadot" <si****@jigsaw. nl> schrieb im Newsbeitrag news:bp******** **@news.tudelft .nl...
berthelot samuel wrote:
Is there a function in C that computes the number of characters in a string.
Yes, it's strlen(). Don't forget #include <string.h>.
I want to be able to compute the number of chars in the string '1 3 4 5' by suppressing the ' ', so length should be 4 instead of 7...
What is the exact text of the problem you have to solve for your course? My guess is that you are taking the wrong approach.
Can it be, that the OP has wide char strings? In this case wcslen() is what he/she needs
Perhaps (that would be a problem for the course in advanced C
programming, I presume).
The OP's question smells like homework - I guess that's what I am trying
to say.
Regards,
Sidney
Irrwahn Grausewitz <ir*******@free net.de> wrote in message news:<ge******* *************** **********@4ax. com>... sa************* *@voila.fr (berthelot samuel) wrote:
Hi, Is there a function in C that computes the number of characters in a string. I want to be able to compute the number of chars in the string '1 3 4 5' by suppressing the ' ', so length should be 4 instead of 7... There's no such standard function, but it's easy to write one yourself. Just lookup the various is...() functions declared in ctype.h and do something like:
#include <ctype.h>
int strGraphCount( const char *s ) { int res = 0;
I'd go with size_t, rather than int.
for( ; *s; ++s ) if ( isgraph( *s ) )
if ( isgraph( (unsigned char) *s ) )
++res; return res; }
HTH Regards
--
Peter ai***@acay.com. au (Peter Nilsson) wrote: Irrwahn Grausewitz <ir*******@free net.de> wrote:
<snip> #include <ctype.h>
int strGraphCount( const char *s ) { int res = 0;
I'd go with size_t, rather than int.
That'd be better design, yes. for( ; *s; ++s ) if ( isgraph( *s ) )
if ( isgraph( (unsigned char) *s ) )
Uck, that was a real mistake, thanks for correction. ++res; return res; }
Regards
--
Irrwahn
(ir*******@free net.de) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ken Fine |
last post by:
Suppose I have strString. I want to determine the length of strString in #
of characters, and write that number of characters on a subsequent line as a
dummy character, say a hypen.
In other words, I want to be able to dynamically create the following
presentation in ASCII:
Title title title title title title
-------------------------
|
by: Nick |
last post by:
Hi,
How can I check if a number exists by itself in this string by using
the RegExp object?
---
var mystring = "11,111,01,011";
var match = "1";
var re = new RegExp( match );
|
by: Raphi |
last post by:
Hi,
I'm trying to clean up a large database in Access. I have one field for
address, which needs to be broken up into Street Number, Street Name, and
Street Label (St., Road, etc.)
The problem is that the data is very dirty. So some addresses will be
standard "456 XYZ Road," while others won't have a number and will just say
"XYZ Industrial Park," meaning I can't just use Instr to search for the
first space because sometimes the...
|
by: shumaker |
last post by:
I see other posts where some say fields that will hold a number with
leading zeros should be stored as text instead of numbers.
This is very inefficient though, as a string of digit characters takes
up much more memory than a 32bit or even a 64bit int.
Storing as a number still allows for formatting when displaying the
number, correct?
I am creating a table and would like opinions regarding this please.
|
by: John S |
last post by:
I have created an event handler that is trying to format each number as it
is typed. Example
If the first char is 1 = output is $1.00
second char is 3 = output is $13.00
next is 5 = $135.00
next is 7 = $1,3576.00
Here is my code but I cannot get it to work.
public static void ReturnFormattedNumber(object sender,
| |
by: Jason |
last post by:
If I've got a string like x = " Intel(R) PRO/1000 CT Network
Connection"
How do I get x = "Intel(R) PRO/1000 CT Network Connection"
I basically want to make a comparison to Intel(R) PRO/1000 CT Network
Connection, since the numeric part seems to change per system.
|
by: Preben Randhol |
last post by:
Hi
If I use len() on a string containing unicode letters I get the number
of bytes the string uses. This means that len() can report size 6 when
the unicode string only contains 3 characters (that one would write by
hand or see on the screen). Is there a way to calculate in characters
and not in bytes to represent the characters.
The reason for asking is that PyGTK needs number of characters to set
the width of Entry widgets to a...
|
by: androoo |
last post by:
Hello all,
I have a string for example :
strTest = "a lineof text (60) witha number in it"
I need to extract the number from between the brackets, the postion of
the number in brackets is never the same...
So in the above example i need to extract 60
|
by: Sharkie |
last post by:
I need a regular expression which will evaluate to false if number of
consecutive characters (non-whitespace) exceeds certain number (10 in
this example).
For example, I have this function:
function test() {
var sValue="short unusuallyLongAndWayTooLongString short2";
var regEx=/\S{10,}/;
return regEx.test(sValue);
|
by: Alexandros H. Halatsis |
last post by:
Let's say I have a cstring: char str = "Hello world";
and I have a needle: char n = "wo";
I find that the needle starts at the 5+1 position of the string.
How am I going to copy the characters up to this point, using the
<cstringheader?
--
Using <string(c++ string) it is possible in two ways:
1) for (int counter = 0; i < str.find(n); i++)
tmp += str;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |