Συντονιστής: konnn


#include <stdio.h>
#include <ctype.h> // isspace()
#define MAXINPUT 255+1
#define MAXWORDS 30+1
#define LENWORD 20+1
int main( void )
{
char input[MAXINPUT] = {'\0'}, words[MAXWORDS][LENWORD] = {{'\0'}};
fgets(input, MAXINPUT, stdin);
char *ch = input, *w, *c;
// w points to current string of the word array, ch to current input character
// and c to the current character of the current string of the word array
for (w = words[0]; w <= words[MAXWORDS-1]; w += LENWORD) {
for (; isspace(*ch); ch++); // skip any blanks
if (! *ch) break;
for (c = w; *ch && ! isspace(*ch); c++, ch++)
*c = *ch;
}
// print reversal
for (int i = MAXWORDS-1; i >= 0; i--)
if (words[i][0])
printf("%s ", words[i]);
putchar('\n');
return 0;
}
this is a string
string a is this 
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define MAXINPUT (255+1)
#define MAXWORDS 30
#define WLEN (20+1)
#define CHR_ACCEPTABLE(ch) ( !isspace( (int)(ch) ) && !ispunct( (int)(ch) ) )
/* ------------------------------------------------------- */
void print_words( char words[][WLEN] )
{
if ( !words || !*words )
return;
for (int i=0; i < MAXWORDS && *(words[i]) != '\0'; i++ )
puts( words[i] );
return;
}
/* ------------------------------------------------------- */
char *s_cpTrim( const char *s )
{
char *cp = (char *)s;
if ( !s )
return NULL;
while ( !CHR_ACCEPTABLE(*cp) )
cp++;
return cp;
}
/* ------------------------------------------------------- */
int main( void )
{
char input[ MAXINPUT ] = {'\0'};
char words[ MAXWORDS ][ WLEN ] = { {'\0'} };
char *cp = NULL, *ws = NULL; /* ws: char-ptr to start of next word */
int iword = 0;
printf("Type your sentence: ");
fgets( input, MAXINPUT, stdin);
/* trim leading non-word chars */
ws = s_cpTrim( input );
iword = 0;
for (cp=ws; *cp && iword < MAXWORDS; cp++)
{
if ( !CHR_ACCEPTABLE(*cp) ) {
*cp++ = '\0';
strncpy( words[iword++], ws, WLEN-1 );
ws = cp = s_cpTrim( cp );
}
}
print_words( words );
system("pause"); /* windows only */
exit( EXIT_SUCCESS );
}


giannosfor έγραψε:Να ρωτήσω κάτι ,από ποιο βιβλίο κάνετε ασκήσεις ;



func("th!is is a long stri!ng", " !")"th", "is", "is", "a", "long", "stri", "ng"