c

 avatar
unknown
plain_text
3 years ago
851 B
2
Indexable
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char str1[100];
    char newString[10][10]; 
    int i,j,ctr;
   
 
    FILE *dosya = fopen("deneme.txt", "r");
    if (dosya == NULL)
        printf("File doesnt exist .");
    
    fgets(str1,100,dosya);	
 
    j=0; ctr=0;
    for(i=0;i<=(strlen(str1));i++)
    {
        // if space or NULL found, assign NULL into newString[ctr]
        if(str1[i]==' '||str1[i]=='\0')
        {
            newString[ctr][j]='\0';
            ctr++;  //for next word
            j=0;    //for next word, init index to 0
        }
        else
        {
            newString[ctr][j]=str1[i];
            j++;
        }
    }
    printf("\n Strings or words after split by space are :\n");
    for(i=0;i < ctr;i++)
        printf(" %s\n",newString[i]);
    fclose(dosya);
    return 0;
}
Editor is loading...