473,836 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strtoint

does this function exist in c? on any equivalent? that convert string to
integer?

how do I convert a array to a "string"
example
char arr['a','b','c'];
char *arr2;

how can I make arr2 = arr ?

Nov 14 '05
35 19635
"Gordon Burditt" <go***********@ burditt.org> wrote in message
news:ce******** @library2.airne ws.net...
trouble me. Why not make an array of the set of characters you want
to be in the random string and then randomly select from the set of


Well they aren't so magic 65 is equal to A and 25 is the range
of the Alphabet :-) so the generated string will be between
(A-Z)


Yes, they *ARE* magic.

C does not guarantee ANY of:

<snip>
The alphabet contains 25 or 26 letters.
There are no unaccented letters in the character set.
<snip>


What do you mean by this, given 5.2.1p3...

Both the basic source and basic execution character sets
shall have the following members: the 26 uppercase letters
of the Latin alphabet
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z
the 26 lowercase letters of the Latin alphabet
a b c d e f g h i j k l m
n o p q r s t u v w x y z
...

--
Peter
Nov 14 '05 #21
Profetas wrote on 26/07/04 :
My goal was to generate a random string, I knew how to generate random
numbers, any way here is my solution.

for(i=0; i<16; i++)
{
var_ptr[i]=65 + rand()%25;
}


Assuming ASCII, you can replace 65 by 'A' and it will work. The trap is
that you have to add a final 0 to make the array of char, a string [1].

A more portable way should be:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main (void)
{
char s[16 + 1];
size_t i;

static char a_alpha[26] = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";

srand ((int) time (NULL));

for (i = 0; i < sizeof s - 1; i++)
{
s[i] = a_alpha[rand () % sizeof a_alpha]; /* assuming A-Z */
}

s[i] = 0;

printf ("s = '%s'\n", s);

return 0;
}

Output:

s = 'NYMLWOBQXZNGHQ IQ'

s = 'LWNWXNLMZIXIBM LF'

---------------------
[1] Maybe it was obvious to you, but in that case, you should have
shown it more clearly.

Additionally, other people, mainly newbies, are reading the newsgroup,
and if they see a code without corrections, they tend to read it as a
valid code. This is why my ethic leads me to avoid to leave bad or
incomplete code without a comment.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"

Nov 14 '05 #22
Profetas wrote on 26/07/04 :
Well that is not a bad approach. However the magic numbers 65 and 25
trouble me.
Well they aren't so magic 65 is equal to A


In ASCII only.
and 25 is the range
of the Alphabet :-) so the generated string will be between
(A-Z)


Used to be 26 to me, but maybe we don't have the same alphabet (I
learnt recently that some letters don't exist in Italian for
example)...

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"

Nov 14 '05 #23
Old Wolf wrote on 26/07/04 :
char arr['a','b','c'];


This is not C.


Actually it is; if the system uses ASCII then it declares an
array of 99 chars.


Error MAIN.C 5: Array bounds missing ]

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"

Nov 14 '05 #24
>> C does not guarantee ANY of:

<snip>
The alphabet contains 25 or 26 letters.
There are no unaccented letters in the character set.
<snip>


What do you mean by this, given 5.2.1p3...

Both the basic source and basic execution character sets
shall have the following members: the 26 uppercase letters
of the Latin alphabet
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z
the 26 lowercase letters of the Latin alphabet
a b c d e f g h i j k l m
n o p q r s t u v w x y z
...


I said: C does not guarantee ANY of
.... there are no unaccented letters in the character set.

Since your quote from the standard demonstrates that there
are at least 52 unaccented letters, it proves my point.

Actually, I meant "C does not guarantee that there are no accented
letters in the character set", but with the mistake the result was
still true.

Gordon L. Burditt
Nov 14 '05 #25
>> Profetas wrote on 25/07/04 :
> char arr['a','b','c'];
Emmanuel Delahaye <em***@YOURBRAn oos.fr> wrote:
This is not C.

In article <84************ **************@ posting.google. com>
Old Wolf <ol*****@inspir e.net.nz> writes:Actually it is; if the system uses ASCII then it declares an
array of 99 chars.


Even in C99, a constant-expression cannot contain a comma-expression:

[#3] Constant expressions shall not contain assignment,
increment, decrement, function-call, or comma operators,
except when they are contained within the operand of a
sizeof operator.83

I have never understood why comma-expressions are forbidden,
although certainly for the code in ">>>" above, a warning is
quite desirable even in non-Standard modes in which comma-expressions
*are* allowed in constants.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #26
Al Bowers <xa******@rapid sys.com> writes:
[...]
This news group is dedicated to the language as defined by the
C Standard(ISO/IEC 9899:1999). Again, I point out that in this
newsgroup, with readers that use various implementations , that
your assertion that 'A' is value 65 is idiotic.


No, it's not idiotic. It's merely incorrect.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #27
Chris Torek <no****@torek.n et> writes:
Profetas wrote on 25/07/04 :
> char arr['a','b','c'];
Emmanuel Delahaye <em***@YOURBRAn oos.fr> wrote:
This is not C.


In article <84************ **************@ posting.google. com>
Old Wolf <ol*****@inspir e.net.nz> writes:
Actually it is; if the system uses ASCII then it declares an
array of 99 chars.


Even in C99, a constant-expression cannot contain a comma-expression:

[#3] Constant expressions shall not contain assignment,
increment, decrement, function-call, or comma operators,
except when they are contained within the operand of a
sizeof operator.83


Right, but in C99 the expression between the square brackets doesn't
have to be a constant-expression, so
char arr['a','b','c'];
declares a variable length array (even though the length can be
determined at compilation time).
I have never understood why comma-expressions are forbidden,
although certainly for the code in ">>>" above, a warning is
quite desirable even in non-Standard modes in which comma-expressions
*are* allowed in constants.


Probably because a constant-expression with a comma operator most
likely indicates a bug. The left operand of a comma operator is
evaluated only for its side effects, and a constant-expression can't
have side effects.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #28
>Chris Torek <no****@torek.n et> writes:
Even in C99, a constant-expression cannot contain a
comma-expression ...

In article <ln************ @nuthaus.mib.or g>
Keith Thompson <ks***@mib.or g> writes:Right, but in C99 the expression between the square brackets doesn't
have to be a constant-expression, so
char arr['a','b','c'];
declares a variable length array (even though the length can be
determined at compilation time).


True, but only if "arr" appears in a context in which VLAs are
allowed. So it is always invalid in C89, and sometimes valid
in C99:

char wrong[1,2]; /* error in both C89 and C99 */
void fn(void) {
char ok_and_VLA[1,2]; /* error in C89, otherwise VLA of size 2 */
...
}

Interestingly, one can test for "VLA-ness" at runtime by applying
the sizeof operator, whose operand *is* evaluated if the operand
is a VLA. I am not quite sure whether this can be used to detect
whether a given C99 compiler treats (1,2) as a constant-expression
in the "ok_and_VLA " case above.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #29


Chris Torek wrote:
Profetas wrote on 25/07/04 :

char arr['a','b','c'];


Emmanuel Delahaye <em***@YOURBRAn oos.fr> wrote:
This is not C.

In article <84************ **************@ posting.google. com>
Old Wolf <ol*****@inspir e.net.nz> writes:
Actually it is; if the system uses ASCII then it declares an
array of 99 chars.

Even in C99, a constant-expression cannot contain a comma-expression:

[#3] Constant expressions shall not contain assignment,
increment, decrement, function-call, or comma operators,
except when they are contained within the operand of a
sizeof operator.83


Because of the comma operator, the expression, ('a','b','c') cannot
be a constant expression. However, vla's do not require a constant
expression and in my opinion the non-constant expression would
be nothing other than a poor construct of the array.

In defect report 261:
http://www.open-std.org/jtc1/sc22/wg...ocs/dr_261.htm
I quote:

"The Committee also agrees that:

int fla [(0+5)]; // is a normal array, not variably modified
int vla [(0,5)]; // is a variable length array"
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2384
by: panther | last post by:
Hi, I need to read part of an integer by another variable. As example, if user enter 761120921, then, i = 761120921 j = 76 k = 112 l = 0921 as that. can you explain how do i acheive this?
1
1403
by: jewel87 | last post by:
Hello, I am working on a program with several classes. It is for storing employee data. I enter all data in the edit boxes in my form, then press a button create new employee and it should store this data in the memory and display in labels. The problem is i am getting an access violation exception at inputting the data into one of the objects. Here is the function for the button: void __fastcall TForm1::CreateEmployeeButtonClick(TObject...
9
1856
by: jewel87 | last post by:
Hi, I have a program with several classes which i was debugging and just found out strange thing: it creates the object in a constructor(class Employee), allocates all memory for other class objects, and then goes straight to the destructor and deallocates all memory just allocated. Only then it goes to the function using this object and gives errors because the memory has just been deallocated. Why is it doing so???? This is the class...
0
9818
marktang
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...
0
10843
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, 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...
0
10254
tracyyun
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...
0
9371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7790
isladogs
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...
0
6978
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();...
0
5648
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...
2
4015
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3112
bsmnconsultancy
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...

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.