Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
/* let say i have a file named word.txt contains 100 words*/
#include<stdio.h>
#include <stdlib.h>
 struct list			//structure function
{
	char word[20];	
};

int main()
{
	struct list n1[100];
	char grid[15][15];
	
	FILE*inp,                      //pointer for input file of encryption.
		*outp;                     //pointer for  output file for encryption.
		 
	int k=0,j=0,i=0,m=0;

	/*  Open file and read the matric number and the name list  */
	inp=fopen("word.txt","r"); 	
	outp=fopen("grib.txt","w");	

	  if (inp == NULL)   //if input is nothing
	  {
              printf("Error opening input file.  \n");
	  }
          else
	  {
              for(k=0;k<100;k++)	
              {
                  fscanf(inp," %s",n1[k].word);                  
                  for(i=0;i<15;i++)	
                  {
                      for(j=0;j<15;j++)				
                      {
                          grid[i][j]=n1[k].word[m];
                          m++; 
                          if(n1[k].word[m]== '\0')
                              break;
                      }
                      m=0; 
                      break;    
                 }
            }
            for(i=0;i<15;i++)	
            {
                for(j;j<15;j++)					
                {
                    grid[i][j]=rand();  
                }
            }
            for(i=0;i<15;i++)	
            {
                for(j=0;j<15;j++)					
                {
                    fprintf (outp,"%s\t\t\t",  grid[i][j]);  
                }
                fprintf (outp,"\n\n\n");  
            }
        }
        system("pause");
        return 0;
    }
Posted
Updated 19-Dec-11 5:22am
v3
Comments
Smithers-Jones 19-Dec-11 10:06am    
What's wrong with your coding? Aren't you the one, who should know that? Any error-message?
baahbie 19-Dec-11 10:28am    
i cant compile it.. no error or warning..
hilmisu 19-Dec-11 10:08am    
what did your compiler says?
baahbie 19-Dec-11 10:29am    
cannot compile.. one compile,windows not responding.
[no name] 19-Dec-11 10:59am    
Cannot compile means what.. what exactly happens when you try to compile. If you still not able to understand what is happening, paste your Output window text here.

After reading your comments, this is starting to sound like your program is just getting stuck (versus not compiling/linking). If that's the case, use a debugger to help you identify the place where you're getting stuck (may be a call that never returns or an infinite loop caused by bad logic).

Your code doesn't have very good formatting when you pasted it onto CodeProject so it's a little hard to read correctly, you may want to fix that to get better help.
 
Share this answer
 
Your program is working: the line
C++
system("pause");
Suspends the current task, so you can look at the output (but in a very inefficient way - use getchar() instead, and always print something alone the lines of "Press any key to continue" before you call it).

It just didn't take very long to execute.
Try adding printf statements before and after each loop to track the progress - you can always take them out later!
 
Share this answer
 
You should somewhere check for EOF character to stop while reading the file.
 
Share this answer
 
Comments
[no name] 20-Dec-11 9:51am    
hey yes that could be the reason. 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900