Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <stdlib.h>
- int main(int argc, const char * argv[]) {
- if(argc < 3) {
- printf("Vlezna i izlezna se vnesuvaat kako argumenti\n");
- return 0;
- }
- FILE *in = fopen(argv[1], "r");
- FILE *out = fopen(argv[2], "w");
- if(in == NULL) {
- printf("Ne validna vlezna datoteka\n");
- return 0;
- }
- if(out == NULL) {
- printf("Ne validna izlezna datoteka\n");
- }
- char s[2000];
- int p = 0;
- while(fgets(s, 1000, in) != NULL) {
- int brojac = 0;
- char zbor[2000];
- int j = 0;
- for(int i = 0; i < strlen(s); i++) {
- if(isspace(s[i]) && s[i] != '\n') {
- for(int k =0 ; k < j; k++) {
- fprintf(out, "%c", zbor[k]);
- }
- if(brojac > 0) {
- fprintf(out, "-");
- }
- else {
- fprintf(out, " ");
- }
- brojac++;
- j = 0;
- }
- else if(s[i] == '\n') {
- for(int k = 0; k < j; k++) {
- fprintf(out, "%c", zbor[k]);
- }
- fprintf(out, ";\n");
- }
- else {
- zbor[j] = s[i];
- j++;
- }
- }
- p++;
- }
- fprintf(out, "%d\n", p);
- return 0;
- }
- /*
- 8
- 1 2 -1 -2 4 3 15 7 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement