Hi everyone,
i made this program. is a simple one for practising malloc, realloc and structs.
I have a struct named shop as global variable in which i take the size of the matrix from the keyboard and after i malloc it.
I insert the values with the fullarray() and after i print the matrix with printproductlist().
After i ask to give from the keyboard to realloc some more rows in the array and again fullarray() and printproductlist().
I compile it with gcc in linux and i get no errors or warnings, things are going well in the run malloc is done and the program gives me the thinks i write into array magazi.
Problems begun when its time for the realloc to be done.
The code is this :
I get a very strange thing in the terminal. Like this :
and after a memory map...
After a few tries i tried the same code in DevCpp in Windows. It works perfectly.
I dont know what kind of problem is this...? Any ideas? Also, if you run it put product names lower than 6 characters.
Windows can let you get away with some very silly things -- for a while. In my early programming days I wrote a music player that crashed on quit, and I couldn't figure out why until I rewrote it for Linux. Because of a logic error, I was deleting my video surface, 60 times per second! And Windows didnt't complain!
Linux checks these things thoroughly, and killed my program the instant it did anything wrong. Much less mysterious.
You're not realloc-ing enough elements. You might even be shrinking your array.
Windows can let you get away with some very silly things -- for a while. In my early programming days I wrote a music player that crashed on quit, and I couldn't figure out why until I rewrote it for Linux. Because of a logic error, I was deleting my video surface, 60 times per second! And Windows didnt't complain!
Linux checks these things thoroughly, and killed my program the instant it did anything wrong. Much less mysterious.
You're not realloc-ing enough elements. You might even be shrinking your array.
So sorry gcc compiler
With my little experience i understood linux are more accurate so they need more accuracy.
You mean that if for example want an array magazi[4] i malloc it with 4 ofcourse and after if i want to make the array magazi[7] i have to realloc it with 7 ? not 3?
Also, problem remains... Exactly the same, after correcting realloc.
What is a shop *? It's a pointer -- something like an integer, to hold one single memory address. It might be 4 bytes, or it might be 8. It certainly isn't 28 bytes.
What is a shop *? It's a pointer -- something like an integer, to hold one single memory address. It might be 4 bytes, or it might be 8. It certainly isn't 28 bytes.
OK.
It work pretty nice now!
Its funny that before some days, when my teacher show me an example of realloc, from where is based this program, i had almost the same question ( why we put * there ) but i dont remember exactly her answer...
Anyway, thanks for your time again
Hi to all,
i'm installing gcc-4.9.0 into my RedHat 6.4 pc. I configure like this :-
# mkdir objdir
# ./../gcc-4.9.0/configure
# make
and now having this problem :-
checking for x86_64-unknown-linux-gnu-gcc... /software/gcc/objdir/./gcc/xgcc -B/software/gcc/objdir/./gcc/... (0 Replies)
Hi,
I just try to solve the problem why one app failing on box1 and runs ok on box2, they have diff gcc version as I see from /proc/version:
box1:: 3.4.1
box2:: 4.1.2
It's RedHat 64b boxes, so I can not run some <make all> command on box1, do you think I need to upgrade (if I'm using... (1 Reply)
Hi guys.
I want to compile three files:
gcc -static main.c fib.c fib.h
it is pure C i mean i use standard C library.
but it gives me this error:
/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
what should i do? (4 Replies)
I just installed gcc from the latest package at sunfreeware.com using pkgadd. I write a simple 'Hello World!' program to test it. I try to compile it and I get this error:
rockstar# gcc hello.c -o hello
ld.so.1: gcc: fatal: libiconv.so.2: open failed: No such file or directory
Killed
I... (0 Replies)
I have a host PC and a target system .
Host System -> gcc (3.2) Redhat linux kernel 2.4.20-8 , glibc 2.3
Target System -> gcc (4.1) Fedora linux kernel 2.6.18-1.2798.fc6, glibc 2.5
I would like to build test program that can be run on both systems
---------------------------
... (0 Replies)
The problem after install gcc on AIX 5.3
I download 5 rpm packages from IBM AIX Toolbox Download Page - Alphabetical Listing and install them.
rpm -ivh gcc-4.0.0-1.aix5.3.ppc.rpm
rpm -ivh libgcc-4.0.0-1.aix5.3.ppc.rpm
rpm -ivh libstdcplusplus-4.0.0-1.aix5.3.ppc.rpm
rpm -ivh... (1 Reply)
Hello All,
I have been using String.h with gcc 2.95. Now I have upgraded to gcc 3.4. The support for String.h has been removed and I believe Regex.h support is also not inbuilt. So I tried to build my own library for String.h. I had to use Regex.h and rx.h for a succesful library compilation.... (0 Replies)
Hi mates,
I am a new comer of this forums.
I have a problem while using function "fread(buffer, size, number, file-pointer)" to read a binary file.
While I used the "fread()" to read the binary file under Solaris UNIX System, it worked very well. But it gets a incorrect result... (6 Replies)
I have some crypting functions in object-file - for example,func.o
Main file,from where crypting functions called, named as main.cpp .
"gcc main.cpp -o main func.o" print "undefined reference to ... "
But if I rename main.cpp to main.c and execute
"gcc main.c -o main func.o" - ok. If anybody,... (3 Replies)
Hi! I have downloaded a precompiled gcc package but I'm having problems installing it. It is supposed to install in /usr/local and there is plenty of space left there but during the installation I get the following error message “No space left on device”. Is it some kind of temp folder that is out... (2 Replies)