Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<ctype.h>
- #include <stdlib.h>
- void writeToFile() {
- FILE *f = fopen("dat.txt", "w");
- char c;
- while((c = getchar()) != '#') {
- fputc(c, f);
- }
- fclose(f);
- }
- int petbukvi( char * red ){
- int count = 0;
- while ( *red ){
- if (isalpha(*red)){
- count++;
- }
- if ( count > 4 ){
- return 1;
- red++;
- }
- }
- return 0;
- }
- void printRow ( char * red, int first, int last ){
- for ( int i = first; i <= last; i++ ){
- if ( i == first ){
- printf("%c", toupper(red[i]));
- }
- else if ( i == last ){
- printf("%c", tolower(red[i]));
- }
- else{
- printf("%c", red[i]);
- }
- }
- }
- void najdiPrvPosleden( char *red ){
- int flag=0, i=0, first, last;
- if (isalpha(red[i])&&flag == 0){
- first = i;
- flag = 1;
- }
- else if ( isalpha(red[i])&&flag ){
- last=i;
- }
- i++;
- }
- int main () {
- writeToFile();
- char red[100], maxRed[100];
- int max=100;
- FILE * file;
- if (( file = fopen("dat.txt", "r")) == NULL ){
- printf("Datotekata ne moze da se otvori");
- exit(-1);
- }
- while((fgets(red, 100, file)) != NULL){
- if ( petbukvi(red) == 1 && strlen(red) < max ){
- max=strlen(red);
- strcpy(maxRed, red);
- }
- }
- fclose(file);
- najdiPrvPosleden(maxRed);
- return 0;
- }
- #include<stdio.h>
- #include<string.h>
- #include<ctype.h>
- void writeToFile() {
- FILE *f = fopen("dat.txt", "w");
- char c;
- while((c = getchar()) != '#') {
- fputc(c, f);
- }
- fclose(f);
- }
- int hasFiveLetter(char *red){
- int count = 0;
- while(*red){
- if(isalpha(*red))
- count++;
- if(count > 4)
- return 1;
- *red++;
- }
- return -1;
- }
- void printRow(char *red, int first, int last){
- for(int i = first; i <= last; i++){
- if(i == first){
- printf("%c", tolower(red[i]));
- }
- else if(i == last){
- printf("%c", tolower(red[i]));
- }
- else{
- printf("%c", red[i]);
- }
- }
- }
- void findFirstLast(char *red){
- int flag = 0, i = 0, first, last;
- while(red[i]){
- if(isalpha(red[i])&&flag == 0){
- first = i;
- flag = 1;
- }
- else if(isalpha(red[i])&&flag == 1){
- last = i;
- }
- i++;
- }
- printRow(red, first, last);
- }
- int main() {
- writeToFile();
- FILE *file = fopen("dat.txt", "r");
- char red[100], maxRed[100];
- int maxLen = 0;
- while(fgets(red, 100, file) != NULL){
- if(hasFiveLetter(red) && strlen(red) >= maxLen){
- maxLen = strlen(red);
- strcpy(maxRed, red);
- }
- }
- fclose(file);
- findFirstLast(maxRed);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement