473,883 Members | 2,607 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 19649

"Martin Ambuhl" <ma*****@earthl ink.net> a écrit dans le message de
news:2m******** ****@uni-berlin.de...

Here we have an example of someone who has not bothered to check even
the most elementary textbook.

Yes. And that is why I didn't bother. Why should we
bother if he doesn't?

Besides, he could have friends...

"Hey man, do not bother to work/learn anything. Just ask in c.l.c and
they will fix it for you..."

Nov 14 '05 #11


Profetas wrote:
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;
}


Well that is not a bad approach. However the magic numbers 65 and 25
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
characters.

Example:

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

#define SZ_STRING 16

int main( void )
{
char *source = "AaBbCcDdEeFfGg HhIiJjKkLlMmNn"
"OoPpQqRrSsTtUu VvWwXxYyZz01234 56789";
char randomstr[SZ_STRING+1];
int i,slen;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );
for(i = 0,slen = strlen(source); i < SZ_STRING;i++)
randomstr[i] = *(source + rand()%slen);
randomstr[SZ_STRING] = '\0'; /* Nul terminate to make a string */
printf("The random string generated is \"%s\"\n",rando mstr);
return 0;
}
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #12
>Well that is not a bad approach. However the magic numbers 65 and 25
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)

Nov 14 '05 #13
"Emmanuel Delahaye" <em***@YOURBRAn oos.fr> wrote in message
news:mn******** *************** @YOURBRAnoos.fr ...

Bare in mind that in C, '=' is the affectation operator,
[On first reading I thought you said affection operator, which I could
really do with. ;-]

I think 'affectation' must be a French/English faux ami.

http://www.m-w.com/cgi-bin/dictionary?affectation
and that '==' is the equal operator (works with numerical values)


It's the 'equal to' equality operator, not to be confused with the simple
assignment operator which consists of a single 'equal' character. Sorry for
the pedantism, but I've heard the assignment operator naively called the
'equal operator' by many newbies, so I think it's worth mentioning what the
true terms and differences are.

Note that equality operators also work operands with with pointer types, as
well as arithmetic types.

--
Peter
Nov 14 '05 #14
"Profetas" <xu*****@yahoo. com> writes:
Well that is not a bad approach. However the magic numbers 65 and 25
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


You shouldn't depend on that.

Nov 14 '05 #15
>>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:

'A' == 65
'A' + 25 == 'Z'
The character set is ASCII.
The alphabet contains 25 or 26 letters.
There are no unaccented letters in the character set.
Alphabetic characters form a contiguous block of consecutive codes.

Gordon L. Burditt
Nov 14 '05 #16


Profetas wrote:
Well that is not a bad approach. However the magic numbers 65 and 25
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)


You know, I have just searched the standard, and I find no mention
of the value of 'A' being 65. But I did find in this paragraph

5.2.1.1
"The values of the members of the execution character set
are implementation-defined."

So you may be using a implementation-defined solution.

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.
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #17
Peter Nilsson wrote on 26/07/04 :
Bare in mind that in C, '=' is the affectation operator,


I think 'affectation' must be a French/English faux ami.


Oops, I meant assignment, of course. Sorry for the Frenchism!

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

"C is a sharp tool"

Nov 14 '05 #18
In article
<5d************ *************** ***@localhost.t alkaboutprogram ming.com>
Profetas <xu*****@yahoo. com> writes:
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)


Except that 'A' is 193 (0xC1), on that IBM mainframe using EBCDIC.
(And yes, it has a C compiler.) Not only that, while 'A'+1 is 'B',
and 'B'+1 is 'C', there is an odd gap so that 'I'+1 is not 'J' --
'J' is coded as 0xD1. There is another gap before the end of the
alphabet, and '0' is coded as 0xF0.
--
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 #19
Emmanuel Delahaye <em***@YOURBRAn oos.fr> wrote:
Profetas wrote on 25/07/04 :
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'];


This is not C.


Actually it is; if the system uses ASCII then it declares an
array of 99 chars.
Nov 14 '05 #20

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
1404
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
1858
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
9933
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
9786
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10407
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
9568
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...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4607
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
2
4211
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
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.