Αυτό ακριβώς κάνει! Φίλε clepto, επειδή σε βλέπω πολύ ορεξάτο (και πολύ χαίρομαι
Η C είναι σίγουρα άριστη επένδυση! Βρίσκεται μόνιμα στο top3-top-5 των δημοφιλέστερων γλωσσών πάνω από 30 χρόνια και αυτό δεν προβλέπεται να αλλάξει σύντομα.
Συντονιστής: konnn



#include <stdio.h>
#include <unistd.h> // POSIX / Unix-only
int fileexists(char *fname) {
if (access(fname, F_OK) != -1) {
return 1; // True, file exists
}
else {
return 0; // False, file doesn't exist
}
}
int main()
{
char *fname = "myfile.txt";
int testfile = fileexists(fname);
if (testfile) { printf("Success! Filename %s exists!\n", fname); }
else if (!testfile) { printf("Oops! Filename %s does not exist.\n", fname); }
return 0;
}
clepto έγραψε:δεν μπορώ να καταλάβω την fgets και πως να την χρησιμοποιήσω![]()


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINE 255+1
#define MAXTOKENS 10
// -----------------------------------------------------------------------------------
char *s_get(char *s, int maxlen)
{
register int i;
for (i=0; (s[i]=getchar()) != '\n' && i < maxlen-1; i++)
; // for-loop with empty body
s[i] = '\0'; // null-terminate s
return s;
}
// -----------------------------------------------------------------------------------
int s_tokenize(char *s, char *tokens[], int maxtokens, char *delimiters)
{
if ( !s || !*s )
return 0;
register int i=0;
tokens[0] = strtok(s, delimiters);
if (tokens[0] == NULL)
return 0;
for (i=1; i < maxtokens && (tokens[i]=strtok(NULL, delimiters)) != NULL; i++)
;
return i;
}
// -----------------------------------------------------------------------------------
int main( void )
{
char linebuf[ MAXLINE ];
char *stokens[ MAXTOKENS ];
int ntokens = 0;
register int i;
printf("Enter up to %d words: ", MAXTOKENS);
s_get( linebuf, MAXLINE);
ntokens = s_tokenize( linebuf, stokens, MAXTOKENS, " \t");
printf("\n%d typed words:\n", ntokens);
for (i=0; i < ntokens; i++)
printf("\t%s\n", stokens[i] );
putchar('\n');
printf("\npress ENTER to exit..."); fflush(stdin); getchar();
exit( EXIT_SUCCESS);
}



#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int guess;
int real;
int yes_no;
real = rand() % 100;
char *game() {
printf("Please type a random number and then hit Enter:\n");
scanf("%d",&guess);
while(guess != real) {
if(guess < real) {
printf("No it is bigger...\n");
}else
{
printf("No it is less...\n");
}
}
}
main() {
do
{
game();
printf("Well done!\nDo you want to play again?(y/n");
} while (scanf("%d",&yes_no) == 'y')
};
main.c:7:1: warning: data definition has no type or storage class
main.c:7:1: error: initializer element is not constant
main.c: In function ‘main’:
main.c:30:1: error: expected ‘;’ before ‘}’ token
main.c:30:1: error: expected declaration or statement at end of input
