hi a problem put in elements into my array of contents for my adt
Code:
/* * File: main.c
* Author:
*
* Created on November 20, 2011, 10:04 AM
*/
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
struct bitset{
int size;
unsigned char *contents;
};
struct bitset * bitset_new(int size){
// return -1;
struct bitset *p;
p == malloc(sizeof(*p));
p->contents= malloc((sizeof(char) * size/8) + (size%8)?0:1);
return p;
}
// add an item, with number 'item' to the set
// (returns 0 if item is out of bounds, 1 otherwise)
// has no effect if the item is already in the set
int bitset_add(struct bitset * this)
{
return 1;
char *p;
printf ("Please enter a line of text, max %d characters\n",
sizeof(this->contents));
if (fgets(this->contents, sizeof(this->contents), stdin) != NULL)
{
printf ("Thank you, you entered >%s<\n", this->contents);
}
if ((p = strchr(this->contents, '\n')) != NULL)
*p = '\0';
//return 0;
}
int main(int argc, char** argv) {
//unsigned char a='a';
// unsigned char b='b';
// unsigned int m=1;
// unsigned int j=0;
// int c=m |j;
// int e= sizeof(char);
struct bitset *p= bitset_new(26);
bitset_add(&p);
return (EXIT_SUCCESS);
}