Pagini recente » Cod sursa (job #1429006) | Cod sursa (job #2168003) | Cod sursa (job #2416674) | Cod sursa (job #2982396) | Cod sursa (job #617582)
Cod sursa(job #617582)
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main ()
{ const int MAX = 256;
char str[100]; char * pch;
fstream f("cuvinte.in",ios::in);
fstream g("cuvinte.out",ios::out);
f.getline(str,MAX);
int nrcuv=0; int lungime=0;
pch = strtok (str," ,.-");
while (pch != NULL)
{ nrcuv++;
lungime+=strlen(pch); //printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
g<<(lungime-1)/nrcuv;
f.close();
g.close();
return 0;
}
/*
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}
*/