<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: char code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 23:21:00 GMT</pubDate>
    <description>DZone Snippets: char code</description>
    <item>
      <title>Include text files in C source</title>
      <link>http://snippets.dzone.com/posts/show/4597</link>
      <description>This includes the contents of myfile.txt into the char array text.&lt;br /&gt;&lt;br /&gt;Note: This only works if ALL lines in the file are enclosed in "s.&lt;br /&gt;&lt;br /&gt;Wrong myfile.txt:&lt;br /&gt;Hello world&lt;br /&gt;Goodbye world&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Right myfile.txt:&lt;br /&gt;"Hello world"&lt;br /&gt;"Goodbyle world"&lt;br /&gt;""&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;char text[] = {&lt;br /&gt;#include "myfile.txt"&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 01 Oct 2007 10:04:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4597</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
    <item>
      <title>Read Multidimensional C char Array of Unknown Length</title>
      <link>http://snippets.dzone.com/posts/show/4034</link>
      <description>Reading a multidimensional C char array (aka C String array) containing char 0 and terminated with literal zero without knowing length.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;char *a[] = { "11", "23", "", "44", "11", "", "16", "36", "", "51", "71", "", "46", "26", "", "14", "68", 0};&lt;br /&gt;int sentinel = 0;&lt;br /&gt;int i = 0;&lt;br /&gt;while ( *(a + i++) != sentinel ) { /* counting away */ }&lt;br /&gt;int aLength = i; // 18, length&lt;br /&gt;int aUbound = i - 1; // 17, index of last element&lt;br /&gt;int aMaxIdx = i - 2; // 16, index of last element where a[i] doesn't cause seg fault&lt;br /&gt;// You now have the lengths so read like normal&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 17 May 2007 00:56:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4034</guid>
      <author>jokeyxero (xero)</author>
    </item>
    <item>
      <title>Python - getchar()</title>
      <link>http://snippets.dzone.com/posts/show/3084</link>
      <description>&lt;code&gt;&lt;br /&gt;import os,sys&lt;br /&gt;import sys&lt;br /&gt;import termios&lt;br /&gt;&lt;br /&gt;def getchar():&lt;br /&gt;	'''&lt;br /&gt;	Equivale al comando getchar() di C&lt;br /&gt;	'''&lt;br /&gt;&lt;br /&gt;	fd = sys.stdin.fileno()&lt;br /&gt;	&lt;br /&gt;	if os.isatty(fd):&lt;br /&gt;		&lt;br /&gt;		old = termios.tcgetattr(fd)&lt;br /&gt;		new = termios.tcgetattr(fd)&lt;br /&gt;		new[3] = new[3] &amp; ~termios.ICANON &amp; ~termios.ECHO&lt;br /&gt;		new[6] [termios.VMIN] = 1&lt;br /&gt;		new[6] [termios.VTIME] = 0&lt;br /&gt;		&lt;br /&gt;		try:&lt;br /&gt;			termios.tcsetattr(fd, termios.TCSANOW, new)&lt;br /&gt;			termios.tcsendbreak(fd,0)&lt;br /&gt;			ch = os.read(fd,7)&lt;br /&gt;&lt;br /&gt;		finally:&lt;br /&gt;			termios.tcsetattr(fd, termios.TCSAFLUSH, old)&lt;br /&gt;	else:&lt;br /&gt;		ch = os.read(fd,7)&lt;br /&gt;	&lt;br /&gt;	return(ch)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 05 Dec 2006 16:16:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3084</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Conteo de caracteres</title>
      <link>http://snippets.dzone.com/posts/show/2661</link>
      <description>Este pedazo de codigo cuenta los caracteres de un archivo&lt;br /&gt;&lt;br /&gt;this code count the chars of a file.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;    int cont[257];&lt;br /&gt;    int t;&lt;br /&gt;    FILE *ent;&lt;br /&gt;    &lt;br /&gt;    for (t=0;t&lt;257;t++)&lt;br /&gt;        cont[t]=0;&lt;br /&gt;      &lt;br /&gt;    ent=fopen("input.txt","r");&lt;br /&gt;//    printf("Se abrio el archivo :P\n");&lt;br /&gt;    do {&lt;br /&gt;        t = fgetc(ent);&lt;br /&gt;        cont[t]++;&lt;br /&gt;    } while (!feof(ent));&lt;br /&gt;    fclose(ent);&lt;br /&gt;&lt;br /&gt;    for (t=0;t&lt;257;t++){&lt;br /&gt;        printf("Caracter %i se repitio %i veces\n", t, cont[t]);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;//  system("PAUSE");	&lt;br /&gt;  return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 22 Sep 2006 20:18:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2661</guid>
      <author>jcongote (John Edgar Congote Calle)</author>
    </item>
    <item>
      <title>Cross platform getch() in python</title>
      <link>http://snippets.dzone.com/posts/show/915</link>
      <description>For Unix, it uses sys, tty, termios modules.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import sys, tty, termios&lt;br /&gt;fd = sys.stdin.fileno()&lt;br /&gt;old_settings = termios.tcgetattr(fd)&lt;br /&gt;tty.setraw(sys.stdin.fileno())&lt;br /&gt;ch = sys.stdin.read(1)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;For Windows, it uses msvcrt module.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import msvcrt&lt;br /&gt;ch = msvcrt.getch()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;See more details and OSX code in this &lt;a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892&gt;recipe&lt;/a&gt; by Danny Yoo.</description>
      <pubDate>Sat, 26 Nov 2005 14:51:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/915</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>pascal triangle plotter XD</title>
      <link>http://snippets.dzone.com/posts/show/440</link>
      <description>&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com&lt;br /&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;conio.h&gt;&lt;br /&gt;&lt;br /&gt;#define MAX 16&lt;br /&gt;&lt;br /&gt;int main () {&lt;br /&gt;	int unsigned vetor[MAX], grau, i = 0, j, top, left;&lt;br /&gt;&lt;br /&gt;	clrscr();&lt;br /&gt;&lt;br /&gt;	printf( "Dado o grau, printar o triangulo de pascal\n" );&lt;br /&gt;&lt;br /&gt;	while( grau &gt; MAX &amp;&amp; printf( "Digite um numero entre 0 e %d para o grau: ", MAX ) &amp;&amp; scanf( "%u", &amp;grau ) );&lt;br /&gt;	while( i++ &lt; grau &amp;&amp; !( j = 0 ) &amp;&amp; printf( "\n" ) )&lt;br /&gt;		while( j &lt; i &amp;&amp; ( j == 0 &amp;&amp; ( top = left = vetor[j] = 1 ) ? 1 : j &gt; 0 &amp;&amp; j &lt; i-1 &amp;&amp; ( top = vetor[j] ) &amp;&amp; ( vetor[j] = left + top ) &amp;&amp; ( left = top ) ? 1 : ( vetor[j] = 1 ) ) &amp;&amp; printf( "%-5d", vetor[j] ) &amp;&amp; ++j );&lt;br /&gt;	getch();&lt;br /&gt;	return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 02 Jul 2005 03:59:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/440</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>palindrome :D</title>
      <link>http://snippets.dzone.com/posts/show/439</link>
      <description>&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com&lt;br /&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt;int isPalindromo( char *s ){&lt;br /&gt;	char *s2 = s + strlen( s ) - 1;&lt;br /&gt;	if( !*s )&lt;br /&gt;		return 1;&lt;br /&gt;	while( *s++ == *s2-- &amp;&amp; *s );&lt;br /&gt;	return !*s &amp;&amp; *( --s ) == *( ++s2 );&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main( int argc, char *argv[] ){&lt;br /&gt;	char s[255];&lt;br /&gt;&lt;br /&gt;	printf( "Texto:" );&lt;br /&gt;	gets( s );&lt;br /&gt;	printf( "%s \n", isPalindromo( s ) ? "YES" : "NO" );&lt;br /&gt;&lt;br /&gt;	system( "pause" );&lt;br /&gt;&lt;br /&gt;	return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 02 Jul 2005 03:57:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/439</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
  </channel>
</rss>
