iam working on program which separates characters by meaning. Currently i got issue with function konverzia. It should add name of day (wed, thu, fri...) to date string, but it doesnt give a shit. Date have to look like this Wed 2012-02-01 Thanks for any ideas.
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
void vstup (int i, char buffer[], int s, int c)
{
printf("\n Type text for analysis: \n ");
scanf ("%80s", buffer); /* Read a string into buffer */
}
void detekcia (int i, char buffer[], int s, int c, int z)
{
while(buffer[i] != '\0') {
if(isalpha(buffer[i]))
s++; /* Increment letter count */
if(isdigit(buffer[i++]))
c++; /* Increment digit count */
if(ispunct(buffer[i++]))
z++;
}
if (s >= 1 && c >= 1)
printf("\n word: %s \n", buffer); /*kombinacia cisla a pismena*/
if (s >= 1 && c == 0)
printf("\n word: %s \n", buffer); /*WORD*/
if (s == 0 && c >= 1 && z == 0)
prvocislo (i,buffer,s,c); /*NUMBER*/
if (s >= 0 && c >= 1 && z >= 1)
datum (i,buffer,s,c,z); /*DATE*/
}
int prvocislo (int i, char buffer[], int s, int c) /*prime number fun*/
{
int x,count=0;
int k = atoi(buffer);
for (x=2; x<=k/2;x++){
if (k%x==0){
count++;
break;
}
}
if (count==0 && k!=1 && k!=0)
printf("\n number: %d (prime)\n",k);
else
printf("\n number: %d",k);
}
int datum (int i, char buffer[], int s, int c, int z)
{
int q = 0;
char d[2];
char m[2];
char r[4];
if (buffer[4]=='-' && buffer[7]=='-')
q++;
if (q==1 && buffer[5]<='1')
q++;
if (q==2 && buffer[8]<='3')
q++;
if (q==3){
q++;
d[1]==buffer[9];
d[0]==buffer[8];
m[1]==buffer[6];
m[0]==buffer[5];
r[3]==buffer[3];
r[2]==buffer[2];
r[1]==buffer[1];
r[0]==buffer[0];
}
if (q==4)
konverzia (d,m,r);
}
int konverzia (char d[], char m[], char r[])
{
int rr = atoi(r);
int dd = atoi(d);
int mm = atoi(m);
int ret;
struct tm info;
char date[10];
info.tm_year = rr - 1900;
info.tm_mon = mm - 1;
info.tm_mday = dd;
info.tm_wday = dd;
ret = mktime(&info);
if (ret == -1){
printf("time error");
}
else{
strftime(date, sizeof(date),"%c",&info);
printf(date);
}
return(0);
}
int main() {
char buffer[80];
int i = 0;
int s = 0; /*pismeno*/
int c = 0; /*cislo*/
int z = 0;
vstup (i,buffer,s,c);
detekcia (i,buffer,s,c,z);
return 0;
}
%c
.