Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Source: malloc.c
- * Program: malloc
- * Version: 1.0.0
- * Target-OS: AmigaOS
- *
- * Purpose: demonstrate dynamic memory allocation
- *
- * Author: Micha B. / 2.11.2022
- *
- * Compiler: SAS/C v6.59
- * Release: sc NOSTACKCHECK OPTIMIZE OPTTIME OPTLOOP CPU=ANY ADDSYM SMALLCODE NOICONS BATCH IDLEN=64 COMNEST STREQ STRMERGE LIB:scnb.lib LIB:amiga.lib
- * Debug: sc NOSTACKCHECK DEBUG=SYMBOLFLUSH NOOPT CPU=ANY ADDSYM SMALLCODE NOICONS BATCH IDLEN=64 COMNEST STREQ STRMERGE LIB:sc:scnb.lib LIB:amiga.lib LIB:debug.lib
- */
- #include <exec/types.h>
- #include <proto/exec.h>
- #include <dos/dos.h>
- #include <proto/dos.h>
- #include <proto/intuition.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h> /* malloc(), calloc(), free() */
- #define SIZE 1024
- int main( int argc, char *argv[] )
- {
- int i=0, length=0;
- //char *teststring = (char *)calloc(SIZE, sizeof(char));
- //char *targetstring = (char *)calloc(SIZE, sizeof(char));
- char *teststring = (char *)malloc(SIZE * sizeof(char));
- char *targetstring = (char *)malloc(SIZE * sizeof(char));
- if(teststring != NULL)
- {
- puts("Memory OK for teststring!");
- }
- else
- {
- puts("No memory left for teststring!");
- return 0;
- }
- if(targetstring != NULL)
- {
- puts("Memory OK for targetstring!");
- }
- else
- {
- puts("No memory left for targetstring!");
- return 0;
- }
- printf("\nI am a test program, dynamically allocating memory...\n");
- #ifdef __STORMGCC__
- printf("Hello, StormGCC!\n");
- #endif
- #ifdef __STORMC__
- printf("Hello, StormC v3!\n");
- #endif
- #ifdef __SASC
- printf("Hello, SAS C!\n");
- #endif
- #ifdef __GNUC__
- printf("Hello, GCC!\n");
- #endif
- #ifdef __VBCC__
- printf("Hello, VBCC!\n");
- #endif
- printf("\nAll Setup Done.\nSkelleton is working. Start coding now!\n\n");
- /* Let's play with the string */
- teststring = "Aa Bb Cc Dd STOP";
- length = strlen(teststring);
- printf("Länge: %ld, sizeof(testring): %ld, teststring: \t\t%s\n", length, sizeof(teststring), teststring);
- /* zeichenweise umkopieren */
- i = 0;
- while(teststring[i] != '\0')
- {
- //printf("i = %ld, teststring[%ld] = %s\n", i, i, &teststring);
- targetstring[i] = teststring[i];
- i++;
- }
- targetstring[i] = 0;
- /* Vergleichsausgabe */
- length = strlen(targetstring);
- printf("Länge: %ld, sizeof(targetstring): %ld, targetstring: \t%s\n", length, sizeof(targetstring), targetstring);
- /* allozierten Speicher freigeben */
- free(targetstring);
- free(teststring);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement