timetraveller92 -8 Light Poster Banned

This code is done using C. Whole point of it is to remove the name just before the first hyphen. Its blindly written so I haven't improved it and it has extra variables and no reuse of variables to save space. If anyone can just locate the error why the printed output has the 1st letter missing then let me know. I will add a system(temp); line to make the renaming possible but for now I have just left a printf to check how the temp value is stored. Help me out here, thanks!

#include<stdio.h>
#include<stdlib.h>
int main()
    {
        int i,j,k,x,y,flag=1;
        FILE *fp;
        char ch=0,location[300],renameto[255],temp[255]="ren ";
        system("dir /b > filx.txt");
        printf("Directory listing saved, beginning renaming operations\n");
        system("ping -n 5 localhost>nul");
        fp=fopen("filx.txt","r");
        while(1)
           {
               for(i=0;ch!='\n';i++)
                   {
                       ch=fgetc(fp);
                       location[i]=ch;
                   }
               location[i-1]=32;
               location[i]='\0';
               for(j=0,k=0;location[j]!='\0';j++,k++)
                    {
                       while(flag)
                         {
                             while(location[j-1]!='-')
                                    j++;
                            flag=0;
                         }
                       renameto[k]=location[j];
                    }
                flag=1;
                renameto[k]='\0';
                for(x=0;location[x]!='\0';x++)
                  temp[x+4]=location[x];
                for(x,y=0;renameto[y]!='\0';x++,y++)
                  temp[x]=renameto[y];
                  temp[x+1]='\0';
               printf("Str: %s\n\n",temp);i=0;
               ch=fgetc(fp);
              if(ch==EOF)
                 break;
           }
           fclose(fp);
           return 0;
    }