![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 | |
|
Newbie
Join Date: Feb 2005
Location: Orlando, FL
Posts: 8
Rep Power: 0
![]() |
gets() produces garbage [would appreciate some more help]
This compiles, but it only produces garbage
any ideas? #include <stdio.h>
#define MAX 20
int counter;
int stack[MAX];
char maze[20][20]; //value at position[h][v]
void push (int x);
int pop(void);
void getvals();
FILE *ifp, *ofp;
int main(void)
{
char filename[13]; //temp filename string
//getting filenames and assigning pointers
printf("\nEnter the name of the maze file.\n");
scanf("%s", filename);
ifp = fopen(filename, "r");
printf("\nEnter the name of the output file.\n");
scanf("%s", filename);
ifp = fopen(filename, "w");
printf("\nOrder of visiting: Up Down Left Right");
getvals(maze);
fclose(ifp);
fclose(ofp);
}
void push (int x)
{
if (counter>MAX)
{
printf("Stack full.\n");
return;
}
stack[counter] = x;
counter++;
}
int pop(void)
{
counter--;
if (counter<0)
{
printf("Stack underflow.\n");
return 0;
}
return stack[counter];
}
void getvals()
{
int i, j;
char tempstring[20];
for (i = 0; i <= 20; i++)
{
fgets(tempstring, 20, ifp);
printf("\n");
for (j = 0; j <= 20; j++)
printf("%c", tempstring[j]);
// *maze[i][j] = tempstring[j];
} // end for (i)
} //end getvals()I'm trying to read this robotfile.txt into a 2-dimensional array Quote:
Last edited by ridley; Feb 24th, 2005 at 1:54 AM. Reason: new problem(s) |
|
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|