EDIT: To clarify this is a question about an error I am getting in gdb, and if it's normal behavior, not about weather local variables can be accessed outside of their scope.
Lately, i have been working through some C exercises. I would compile my programs like this -
gcc -g -o ../bin/prog prog.c
And they would be debugged like this -
gdb ../bin/prog
(gdb) run < ../bin/input
However every time I do this, I run into close to if not the same error -
Starting program: /home/user/workspace/c exercises/prog/bin/prog < ../bin/input
Program received signal SIGSEGV, Segmentation fault.
__strlen_ia32 () at ../sysdeps/i386/i686/multiarch/../../i586/strlen.S:94
94 ../sysdeps/i386/i686/multiarch/../../i586/strlen.S: No such file or directory
Below is the corresponding source for this specific occurrence, I am running Debian 9 i386. I don't think it's related to my program being incorrect as I get the same error with programs that work. It's always that it cannot find some .so or .S file. Thanks in advance.
/** Exercise 1-19
*
* Write a function reverse(s) that reverses the character string s.
* Use it to write a program that reverses its input a line at a time.
*/
#include <stdio.h>
#define MAX 1000
int getLine(char*,int);
char* reverse(char*);
int main()
{
char line[MAX];
while(getLine(line, MAX) > 0)
puts(reverse(line));
}
int getLine(char s[], int lim)
{
int c,i;
for(i=0;(c=getchar())!=EOF && c!='\n';i++)
s[i] = c;
if(c == '\n')
s[i++] == '\n';
s[i] = '\0';
return i;
}
char* reverse(char s[])
{
char rev[MAX];
int i;
for(i=MAX-1; s[i]!='\0' && i >= 0; i--);
for(int j=1; j<=i; j++)
rev[j] = s[i-j];
rev[i] = '\0';
return rev;
}