C/C++ Beginner's Guide and Post Basic Questions here

Nerevarine

Incarnate
ncurses is the modern implementation of curses, sorry I am out of touch. I myself have never implemented ncurses :(, you should google for better answers (or wait for people here).
 

quicky008

Technomancer
#include<stdio.h>

struct abc{

int a[5];
float b;

};



int main()
{

struct abc obj={

.a={
{0,1,2,3,4}

},

.b=2.5


};


printf("%d",obj.b);


}

Is this code correct?When i am trying to print the value of obj.b,its outputting 0.Shouldn't it display 2.5 (as the variable was initialized to 2.5 earlier)?
 
Last edited:

quicky008

Technomancer
if there is a string say char s[]="ABCD" and a pointer called char *ptr,how can i obtain the reverse of this string s and store it in ptr?
 

Nerevarine

Incarnate
just reverse the string by your favourite algo and store the entire string in the ptr

char *ptr is a different notation for char[]. Both are interchangeable.

Also, this is how you access indexes incase of char
Both LHS and RHS mean same thing
char *ptr + sizeof(char)*i = str squarebracket i squarebracket
 

quicky008

Technomancer
No i was wondering how i could reverse the string using a pointer only,not by any other means.Should have specified it clearly earlier.
 

quicky008

Technomancer
i can calculate that using strlen and assign it to a dynamically allocated memory for storing character type data(that was created using malloc).Then my plan is to reverse the string and store it in this newly allocated memory space,the size of which is same as that of the original string

today someone gave me this makefile for a particular project:

CFLAGS = gcc -std=c11 -Werror -Wall -Wconversion
LDLIBS = -lcurses -lm
OUTPUT = game
all: $(OUTPUT)

$(OUTPUT): main.o hof.o k.o ui.o
gcc $(CFLAGS) main.o hof.o k.o ui.o $(LDLIBS) -o $(OUTPUT)

main.o: main.c
gcc $(CFLAGS) -c main.c -o main.o

hof.o: hof.c hof.h
gcc $(CFLAGS) -c hof.c -o hof.o

k.o: k.c k.h
gcc $(CFLAGS) -c k.c -o k.o

ui.o: ui.c ui.h
gcc $(CFLAGS) -c ui.c -o ui.o
clean:
rm -r *.o

Can anybody explain whats going on here?I primarily do all my c programming under windows and thus i dont have much knowledge of makefiles.
 
Top Bottom