<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://so.v2.cs.unibo.it/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=F.Mastromarino</id>
	<title>Sistemi Operativi - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://so.v2.cs.unibo.it/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=F.Mastromarino"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php/Special:Contributions/F.Mastromarino"/>
	<updated>2026-05-05T08:26:46Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Esercizio_1,_prova_pratica_20/02/2014&amp;diff=909</id>
		<title>Esercizio 1, prova pratica 20/02/2014</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Esercizio_1,_prova_pratica_20/02/2014&amp;diff=909"/>
		<updated>2015-03-17T11:07:08Z</updated>

		<summary type="html">&lt;p&gt;F.Mastromarino: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Scrivere un programma in C “colonnan” che prenda come parametro il pathname di un file e un numero intero (che&lt;br /&gt;
chiameremo n). Il programma deve stampare come output il numero di caratteri presenti nella n-ma colonna del file se il file e'&lt;br /&gt;
un file regolare di testo, non deve stampare nulla negli altri casi. Un file viene considerato di testo se tutti i suoi byte hanno&lt;br /&gt;
valori compresi nel range 1-127. Per controllare se il file e' “regolare” usare la system call lstat.&lt;br /&gt;
&lt;br /&gt;
==Soluzione di DBoldrin==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main(int argc, char* argv[]){&lt;br /&gt;
   FILE *fp;&lt;br /&gt;
   char* pathname = argv[1];&lt;br /&gt;
   int contachar=0;&lt;br /&gt;
   int contacolonna=0;&lt;br /&gt;
   char carattere[2];&lt;br /&gt;
   int n=atoi(argv[argc-1]);&lt;br /&gt;
   int c;&lt;br /&gt;
&lt;br /&gt;
   fp = fopen(pathname,&amp;quot;r&amp;quot;); // read mode&lt;br /&gt;
 &lt;br /&gt;
   if( fp == NULL )&lt;br /&gt;
   {&lt;br /&gt;
      perror(&amp;quot;Error while opening the file.\n&amp;quot;);&lt;br /&gt;
      exit(EXIT_FAILURE);&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   printf(&amp;quot;il numero di elementi nella colonna %d del file %s sono:\n&amp;quot;,n,pathname);&lt;br /&gt;
 &lt;br /&gt;
  while ((c= getc(fp)) != EOF) {&lt;br /&gt;
        if ((carattere[1] = c) == '\n')&lt;br /&gt;
		contacolonna=0;      &lt;br /&gt;
    else&lt;br /&gt;
	contacolonna++;&lt;br /&gt;
	if(contacolonna==n){&lt;br /&gt;
		contachar++;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}	&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;,contachar);&lt;br /&gt;
   fclose(fp);&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Soluzione di F.Mastromarino e LorenzoV==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){&lt;br /&gt;
	int cont=0; int c; int colonna=atoi(argv[1]); int cont2=0;&lt;br /&gt;
	char *path=&amp;quot;/home/francesco/Scrivania/stampa.txt&amp;quot;;&lt;br /&gt;
	int fd=open(path, O_RDONLY, 0664); //0664 sono i permessi per la sola lettura&lt;br /&gt;
	fd=dup2(fd, STDIN_FILENO); //file stampa.txt come standard input&lt;br /&gt;
	struct stat buf;&lt;br /&gt;
	if(lstat(path, &amp;amp;buf)&amp;lt;0 &amp;amp;&amp;amp; (buf.st_mode &amp;amp; S_IFMT)!=S_IFREG) // il campo st_mode indica il tipo di file e la costante S_IFREG &lt;br /&gt;
//contiene il valore di un file regolare(0100000), S_IFMT è la maschera di bit usata per controllare il tipo di file&lt;br /&gt;
		return(-1);&lt;br /&gt;
	do{&lt;br /&gt;
		cont=0;&lt;br /&gt;
		do{&lt;br /&gt;
			&lt;br /&gt;
			c=getchar(); // legge un carattere da file e lo ritorna come un intero&lt;br /&gt;
			if(c!= EOF &amp;amp;&amp;amp; (c&amp;gt;127 || c&amp;lt;1)){ // controllo se è un file ASCII&lt;br /&gt;
				printf(&amp;quot;Non regolare\n&amp;quot;);&lt;br /&gt;
			return(-1);&lt;br /&gt;
		}&lt;br /&gt;
			cont++;&lt;br /&gt;
			if(cont==colonna) cont2++;&lt;br /&gt;
		}while(c!='\n' &amp;amp;&amp;amp; c!=EOF);&lt;br /&gt;
	}while(c!=EOF); // EOF è l'ultimo carattere del file da leggere&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;, cont2);&lt;br /&gt;
	close(fd);&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
--[[User:F.Mastromarino|F.Mastromarino]] ([[User talk:F.Mastromarino|talk]]) 11:14, 17 March 2015 (CET)&lt;/div&gt;</summary>
		<author><name>F.Mastromarino</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Esercizio_1,_prova_pratica_20/02/2014&amp;diff=908</id>
		<title>Esercizio 1, prova pratica 20/02/2014</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Esercizio_1,_prova_pratica_20/02/2014&amp;diff=908"/>
		<updated>2015-03-17T10:14:18Z</updated>

		<summary type="html">&lt;p&gt;F.Mastromarino: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Soluzione di DBoldrin==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main(int argc, char* argv[]){&lt;br /&gt;
   FILE *fp;&lt;br /&gt;
   char* pathname = argv[1];&lt;br /&gt;
   int contachar=0;&lt;br /&gt;
   int contacolonna=0;&lt;br /&gt;
   char carattere[2];&lt;br /&gt;
   int n=atoi(argv[argc-1]);&lt;br /&gt;
   int c;&lt;br /&gt;
&lt;br /&gt;
   fp = fopen(pathname,&amp;quot;r&amp;quot;); // read mode&lt;br /&gt;
 &lt;br /&gt;
   if( fp == NULL )&lt;br /&gt;
   {&lt;br /&gt;
      perror(&amp;quot;Error while opening the file.\n&amp;quot;);&lt;br /&gt;
      exit(EXIT_FAILURE);&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   printf(&amp;quot;il numero di elementi nella colonna %d del file %s sono:\n&amp;quot;,n,pathname);&lt;br /&gt;
 &lt;br /&gt;
  while ((c= getc(fp)) != EOF) {&lt;br /&gt;
        if ((carattere[1] = c) == '\n')&lt;br /&gt;
		contacolonna=0;      &lt;br /&gt;
    else&lt;br /&gt;
	contacolonna++;&lt;br /&gt;
	if(contacolonna==n){&lt;br /&gt;
		contachar++;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}	&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;,contachar);&lt;br /&gt;
   fclose(fp);&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Soluzione di F.Mastromarino e LorenzoV==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){&lt;br /&gt;
	int cont=0; int c; int colonna=atoi(argv[1]); int cont2=0;&lt;br /&gt;
	char *path=&amp;quot;/home/francesco/Scrivania/stampa.txt&amp;quot;;&lt;br /&gt;
	int fd=open(path, O_RDONLY, 0664); //0664 sono i permessi per la sola lettura&lt;br /&gt;
	fd=dup2(fd, STDIN_FILENO); //file stampa.txt come standard input&lt;br /&gt;
	struct stat buf;&lt;br /&gt;
	if(lstat(path, &amp;amp;buf)&amp;lt;0 &amp;amp;&amp;amp; (buf.st_mode &amp;amp; S_IFMT)!=S_IFREG) // il campo st_mode indica il tipo di file e la costante S_IFREG &lt;br /&gt;
//contiene il valore di un file regolare(0100000), S_IFMT è la maschera di bit usata per controllare il tipo di file&lt;br /&gt;
		return(-1);&lt;br /&gt;
	do{&lt;br /&gt;
		cont=0;&lt;br /&gt;
		do{&lt;br /&gt;
			&lt;br /&gt;
			c=getchar(); // legge un carattere da file e lo ritorna come un intero&lt;br /&gt;
			if(c!= EOF &amp;amp;&amp;amp; (c&amp;gt;127 || c&amp;lt;1)){ // controllo se è un file ASCII&lt;br /&gt;
				printf(&amp;quot;Non regolare\n&amp;quot;);&lt;br /&gt;
			return(-1);&lt;br /&gt;
		}&lt;br /&gt;
			cont++;&lt;br /&gt;
			if(cont==colonna) cont2++;&lt;br /&gt;
		}while(c!='\n' &amp;amp;&amp;amp; c!=EOF);&lt;br /&gt;
	}while(c!=EOF); // EOF è l'ultimo carattere del file da leggere&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;, cont2);&lt;br /&gt;
	close(fd);&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
--[[User:F.Mastromarino|F.Mastromarino]] ([[User talk:F.Mastromarino|talk]]) 11:14, 17 March 2015 (CET)&lt;/div&gt;</summary>
		<author><name>F.Mastromarino</name></author>
	</entry>
</feed>