<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=4&amp;t=11179&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2015-03-26T09:04:20+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=11179&amp;mode</id>
<entry>
<author><name><![CDATA[Marvinn8686]]></name></author>
<updated>2015-03-26T09:04:20+01:00</updated>
<published>2015-03-26T09:04:20+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124662#p124662</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124662#p124662"/>
<title type="html"><![CDATA[Re: czy srting to liczba?]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124662#p124662"><![CDATA[
W przypadku atoi problem jest taki, że zwraca 0 w dwóch przypadkach - jeśli ciąg, który konwertujemy faktycznie zawiera &quot;0&quot;, oraz gdy konwersja się nie powiedzie.<br /><div class="quotetitle"><b>Quote:</b></div><div class="quotecontent"><br />The function returns the converted integral number as an int value, if successful. If no valid conversion could be performed then an zero value is returned.<br /></div><br /><br />Można jeszcze użyć sscanf:<br />[syntax=c]char *str = &quot;555684&quot;;<br />int number;<br />int result = sscanf( str, &quot;%d&quot;, &amp;number);[/syntax]<br />Po czym sprawdzić wartość zmiennej result zwróconej przez sscanf.<br /><div class="quotetitle"><b>Quote:</b></div><div class="quotecontent"><br />On success, the function returns the number of items in the argument list successfully filled.<br /></div><br />To rozwiązanie radzi sobie ze spacjami, tj. &quot; 5678 &quot; zostanie rozpoznane jako 5678 (result = 1)<br />Błędny ciąg &quot;afdffadf&quot; zostanie rozpoznany (result = 0).<br />Niestety wadą tego podejścia jest, że ciąg &quot;1234blabla&quot; zostanie rozpoznany jako 1234 (result = 1)<br /><br />edit.<br />Jesli nie interesuje Cię sama wartość, a potrzebujesz tylko informacji czy ciąg jest liczbą typu int<br /><a href="http://stackoverflow.com/a/9753581"  class="postlink">http://stackoverflow.com/a/9753581</a><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1232">Marvinn8686</a> — 26 mar 2015, o 09:04</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[xor]]></name></author>
<updated>2015-03-25T21:36:03+01:00</updated>
<published>2015-03-25T21:36:03+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124640#p124640</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124640#p124640"/>
<title type="html"><![CDATA[Re: czy srting to liczba?]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124640#p124640"><![CDATA[
Może jakoś tak:<br /><br />[syntax=c]#include &lt;string.h&gt;<br /><br />char *str = &quot;555684&quot;;<br />...<br />if(strspn(str, &quot;1234567890&quot;)==strlen(str))<br />{<br />    ... mamy liczbe...<br />}[/syntax]<br /><br />No tak, ale co ze spacjami, które mogą się zaplątać na początku albo na końcu ciągu a które atoi elegancko usuwa? <br />To może tak:<br /><br />[syntax=c]#include &lt;string.h&gt;<br />char *str = &quot;  555684\n&quot;;<br /><br />char *ltrim(char *str)<br />{<br />   int c2t = strspn(str, &quot; \t\n&quot;);<br />   return c2t ? strcpy( str, str + c2t ) : str;<br />}<br /><br />char *rtrim(char *str)<br />{<br />    (void)strrev(str);<br />    return strcpy(str, strrev(str + strspn(str, &quot; \t\n&quot;)));<br />}<br /><br />...<br /><br />if(strspn( ltrim( rtrim( str ) ), &quot;1234567890&quot;)==strlen( ltrim( rtrim( str ) ) ))<br />{<br />    ... mamy liczbe...<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1774">xor</a> — 25 mar 2015, o 21:36</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[anshar]]></name></author>
<updated>2015-03-25T20:52:02+01:00</updated>
<published>2015-03-25T20:52:02+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124627#p124627</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124627#p124627"/>
<title type="html"><![CDATA[Re: czy srting to liczba?]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124627#p124627"><![CDATA[
Zobacz np. <a href="http://www.codingunit.com/c-reference-stdlib-h-function-atoi-convert-a-string-to-an-integer"  class="postlink">http://www.codingunit.com/c-reference-stdlib-h-function-atoi-convert-a-string-to-an-integer</a><br />Dodajesz bibliotekę stdlib.h<br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 8 minutach ]</span></strong><br /><br /><a href="http://cboard.cprogramming.com/cplusplus-programming/33859-how-can-i-determine-whether-string-represents-integer-not.html"  class="postlink">http://cboard.cprogramming.com/cplusplus-programming/33859-how-can-i-determine-whether-string-represents-integer-not.html</a><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=7157">anshar</a> — 25 mar 2015, o 20:52</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[asek5]]></name></author>
<updated>2015-03-25T20:45:30+01:00</updated>
<published>2015-03-25T20:45:30+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124626#p124626</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124626#p124626"/>
<title type="html"><![CDATA[czy string to liczba? jak sprawdzić.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=11179&amp;p=124626#p124626"><![CDATA[
Witam <br />Chce sprawdzić czy string to liczba, czyli string zamieniam na int funkcja atoi i pytanie co dalej. Jest coś takiego w c. PHP posiada gotowce do sprawdzenia ale w c nie mogę znaleźć.<br /><br /><span style="color: #FF0000">Uprasza się o mniejsze niedbalstwo, czeski błąd w tytule to już zwykłe lenistwo!<br /></span><span style="color: #80FF00">rezasurmar</span><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=5515">asek5</a> — 25 mar 2015, o 20:45</p><hr />
]]></content>
</entry>
</feed>