<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://so.v2.cs.unibo.it/wiki/index.php?action=history&amp;feed=atom&amp;title=Prove_pratiche_2016</id>
	<title>Prove pratiche 2016 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://so.v2.cs.unibo.it/wiki/index.php?action=history&amp;feed=atom&amp;title=Prove_pratiche_2016"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche_2016&amp;action=history"/>
	<updated>2026-05-01T02:13:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche_2016&amp;diff=2581&amp;oldid=prev</id>
		<title>Acsor: Created page with &quot; == Esame Pratico 22/01/2016 == http://www.cs.unibo.it/~renzo/so/pratiche/2016.01.22.pdf === Esercizio 1 === &lt;source lang=&quot;c&quot;&gt; #include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; #include ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche_2016&amp;diff=2581&amp;oldid=prev"/>
		<updated>2020-08-30T08:14:09Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; == Esame Pratico 22/01/2016 == http://www.cs.unibo.it/~renzo/so/pratiche/2016.01.22.pdf === Esercizio 1 === &amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include &amp;lt;stdio.h&amp;gt; #include ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== Esame Pratico 22/01/2016 ==&lt;br /&gt;
http://www.cs.unibo.it/~renzo/so/pratiche/2016.01.22.pdf&lt;br /&gt;
=== Esercizio 1 ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef struct nameNumber {&lt;br /&gt;
        char *name;&lt;br /&gt;
        int value;&lt;br /&gt;
} nameNumber;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int prefixToInt (char *string) {&lt;br /&gt;
    int i = 0;&lt;br /&gt;
    int num = 0;&lt;br /&gt;
&lt;br /&gt;
    while (string[i] &amp;gt;= '0' &amp;amp;&amp;amp; string[i] &amp;lt; '9' &amp;amp;&amp;amp; i &amp;lt; strlen(string)) {&lt;br /&gt;
        num = (num*10) + (string[i]-'0');&lt;br /&gt;
        i++;&lt;br /&gt;
    }&lt;br /&gt;
    return num;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void fileSort(struct nameNumber **files) {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int comp (const void * el1, const void * el2) {&lt;br /&gt;
    struct nameNumber *f = *((nameNumber**)el1);&lt;br /&gt;
    struct nameNumber *s = *((nameNumber**)el2);&lt;br /&gt;
    if (f-&amp;gt;value &amp;gt; s-&amp;gt;value) return 1;&lt;br /&gt;
    if (f-&amp;gt;value &amp;lt; s-&amp;gt;value) return -1;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int arg, char* argv[]) {&lt;br /&gt;
    struct nameNumber **files;&lt;br /&gt;
&lt;br /&gt;
    DIR *dir;&lt;br /&gt;
    struct dirent *ent;&lt;br /&gt;
&lt;br /&gt;
    int count = 0;&lt;br /&gt;
&lt;br /&gt;
    if((dir = opendir(argv[1])) != NULL) &lt;br /&gt;
    {&lt;br /&gt;
        while( (ent = readdir(dir)) != NULL ) &lt;br /&gt;
        {   &lt;br /&gt;
            if (ent-&amp;gt;d_name[0] &amp;lt; '9' &amp;amp;&amp;amp; ent-&amp;gt;d_name[0] &amp;gt;= '0') &lt;br /&gt;
            {&lt;br /&gt;
                files = (struct nameNumber**)realloc(files , (count+1) * sizeof(struct nameNumber*));&lt;br /&gt;
                files[count] = (struct nameNumber*)malloc(sizeof(struct nameNumber));&lt;br /&gt;
                files[count]-&amp;gt;name = (char*)malloc(sizeof(char)*strlen(ent-&amp;gt;d_name) + 1);&lt;br /&gt;
                strcpy(files[count]-&amp;gt;name, ent-&amp;gt;d_name);&lt;br /&gt;
                files[count]-&amp;gt;value = prefixToInt(files[count]-&amp;gt;name);&lt;br /&gt;
                printf(&amp;quot;name : %s  ,  value : %d\n&amp;quot;, files[count]-&amp;gt;name , files[count]-&amp;gt;value);&lt;br /&gt;
                count++;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    qsort(files, count, sizeof(nameNumber*), comp);&lt;br /&gt;
&lt;br /&gt;
    int i;&lt;br /&gt;
    for (i=0; i &amp;lt; count; i++) {&lt;br /&gt;
        printf(&amp;quot;%s\n&amp;quot;,files[i]-&amp;gt;name);&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Acsor</name></author>
	</entry>
</feed>