Click here to Skip to main content
16,015,032 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Determine if a string is a number Pin
Ravi Bhavnani27-May-02 7:50
professionalRavi Bhavnani27-May-02 7:50 
GeneralRe: Determine if a string is a number Pin
Matt Gullett27-May-02 7:58
Matt Gullett27-May-02 7:58 
GeneralRe: Determine if a string is a number Pin
Anders Molin27-May-02 10:12
professionalAnders Molin27-May-02 10:12 
GeneralRe: Determine if a string is a number Pin
l a u r e n27-May-02 11:57
l a u r e n27-May-02 11:57 
GeneralRe: Determine if a string is a number Pin
Steve L.27-May-02 13:57
Steve L.27-May-02 13:57 
GeneralRe: Determine if a string is a number Pin
Ernest Laurentin28-May-02 6:11
Ernest Laurentin28-May-02 6:11 
GeneralRe: Determine if a string is a number Pin
Mike Nordell28-May-02 15:55
Mike Nordell28-May-02 15:55 
Generalqueue of buffers Pin
starnx27-May-02 7:10
starnx27-May-02 7:10 
Hi, if somebody could just give a look at this code :
Iknow it's not C++, it's only C....
I don't know what I do wrong....

Thanks a lot Smile | :)

Starn

[code]
/* This little piece of code initiate 2 queue
**First queue is filled of empty buffers
**second queue is filled with the full buffers
**PROBLEM : I can only fill the 2 first buffers in the FOR loop
** queueX.h contains the TAILQ macros. (see after the main function...)
*/
//I know, I don't need all these includes... (it's for other functions...)

#include <stdio.h>
#include <unistd.h>
#include <atomic.h>
#include <malloc.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <net/if_types.h>
#include <netinet/in.h>
#include <sys/syspage.h>
#include <sys/neutrino.h>
#include <syslog.h>
#include <sys/dispatch.h>
#include <sys/io-net.h>

#include <string.h>
#include <stdbool.h>

#include<sys/queueX.h>


#define NB_BY 192 // 192 bytes = 1536 bits = 2x 48 échantillons de 16 bits car 1 ms = 2 x 48 ech à 48000Hz

int msg_thread_send;


TAILQ_HEAD(buffers,entry) head;
struct buffers *headp;

struct entry{
char data[NB_BY];
TAILQ_ENTRY(entry) entries;
} *n1, *n2, *n3,*n4,*n5, *np,*sendp,*ready_sendp;

TAILQ_HEAD(send,entry) head_send;
struct send *head_sendp;


int main()
{

FILE *file1;
int i, file_size;

if ((file1 = fopen ("/home/s_16_44.wav", "r")) == 0)
printf ("can not open file\n ");
fseek(file1, 0, SEEK_END);
file_size=ftell(file1);
fseek(file1, 48, SEEK_SET);


TAILQ_INIT (&head);
TAILQ_INIT (&head_send);

n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
TAILQ_INSERT_HEAD(&head, n1, entries);

n2 = malloc(sizeof(struct entry)); /* Insert at the tail. */
TAILQ_INSERT_AFTER(&head, n1,n2, entries);
//TAILQ_INSERT_TAIL(&head, n1, entries);

n3 = malloc(sizeof(struct entry)); /* Insert at the tail. */
TAILQ_INSERT_AFTER(&head, n2,n3, entries);
//TAILQ_INSERT_TAIL(&head, n4, entries);


n4 = malloc(sizeof(struct entry)); /* Insert at the tail. */
TAILQ_INSERT_AFTER(&head,n3, n4, entries);
//TAILQ_INSERT_TAIL(&head, n4, entries);


n5 = malloc(sizeof(struct entry)); /* Insert at the tail. */
TAILQ_INSERT_TAIL(&head, n5, entries);



for (np = head.tqh_first; np != NULL; np = np->entries.tqe_next)
{
fread(np->data,NB_BY,1,file1);

if(np=head.tqh_first)
{
TAILQ_INSERT_HEAD(&head_send, np, entries);
printf("insert_head\n");
}
else
TAILQ_INSERT_TAIL(&head_send, np, entries);
printf("insert_queue\n");

}

np=head.tqh_first;
//ready_sendp=head_send.tqh_first;

// ICI, démarrer le thread_send

while(1)
{
if(msg_thread_send) //tant que le thread_send n'a pas mis ce bit à , il n'y a pas de buffer de libre
{
fread(np->data,NB_BY,1,file1);
// if(j>4)
//{


TAILQ_INSERT_TAIL(&head_send, np, entries);
//voir si il ne faut pas retirer le premier élément de la queue_send (memory leacks) ca devrait être arrangé avec TAILQ_REMOVE

np = np->entries.tqe_next;
msg_thread_send=0;
}

if( np == NULL) //si on est au bout de la queue, on revient au début...
np=head.tqh_first;



}

// printf("data : %c\n",n1->data);

fclose(file1);




return(0);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
* Tail queue declarations.
*/
#define TAILQ_HEAD(name, type) \
struct name { \
struct type *tqh_first; /* first element */ \
struct type **tqh_last; /* addr of last next element */ \
}

#define TAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).tqh_first }

#define TAILQ_ENTRY(type) \
struct { \
struct type *tqe_next; /* next element */ \
struct type **tqe_prev; /* address of previous next element */ \
}

/*
* Tail queue functions.
*/
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)

#define TAILQ_FIRST(head) ((head)->tqh_first)

#define TAILQ_FOREACH(var, head, field) \
for ((var) = TAILQ_FIRST((head)); \
(var); \
(var) = TAILQ_NEXT((var), field))

#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for ((var) = TAILQ_LAST((head), headname); \
(var); \
(var) = TAILQ_PREV((var), headname, field))

#define TAILQ_INIT(head) do { \
TAILQ_FIRST((head)) = NULL; \
(head)->tqh_last = &TAILQ_FIRST((head)); \
} while (0)

#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
TAILQ_NEXT((elm), field)->field.tqe_prev = \
&TAILQ_NEXT((elm), field); \
else \
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
TAILQ_NEXT((listelm), field) = (elm); \
(elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
} while (0)

#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
TAILQ_NEXT((elm), field) = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
} while (0)

#define TAILQ_INSERT_HEAD(head, elm, field) do { \
if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
TAILQ_FIRST((head))->field.tqe_prev = \
&TAILQ_NEXT((elm), field); \
else \
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
TAILQ_FIRST((head)) = (elm); \
(elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
} while (0)

#define TAILQ_INSERT_TAIL(head, elm, field) do { \
TAILQ_NEXT((elm), field) = NULL; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
} while (0)

#define TAILQ_LAST(head, headname) \
(*(((struct headname *)((head)->tqh_last))->tqh_last))

#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)

#define TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))

#define TAILQ_REMOVE(head, elm, field) do { \
if ((TAILQ_NEXT((elm), field)) != NULL) \
TAILQ_NEXT((elm), field)->field.tqe_prev = \
(elm)->field.tqe_prev; \
else \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
} while (0)
[/code]
QuestionHow to return C++ Class pointer in COM interface? Pin
Uttam Kumar Unik!27-May-02 5:52
Uttam Kumar Unik!27-May-02 5:52 
AnswerRe: How to return C++ Class pointer in COM interface? Pin
Paul M Watt27-May-02 6:09
mentorPaul M Watt27-May-02 6:09 
GeneralRe: How to return C++ Class pointer in COM interface? Pin
Uttam Kumar Unik!27-May-02 21:42
Uttam Kumar Unik!27-May-02 21:42 
AnswerRe: How to return C++ Class pointer in COM interface? Pin
Le centriste28-May-02 7:57
Le centriste28-May-02 7:57 
GeneralListbox sorting Pin
_Magnus_27-May-02 5:38
_Magnus_27-May-02 5:38 
GeneralSubject: Flickering (A problem for EVER) Pin
Hadi Rezaee27-May-02 5:09
Hadi Rezaee27-May-02 5:09 
GeneralRe: Subject: Flickering (A problem for EVER) Pin
Erik Funkenbusch27-May-02 5:16
Erik Funkenbusch27-May-02 5:16 
GeneralRe: Subject: Flickering (A problem for EVER) Pin
Hadi Rezaee27-May-02 6:36
Hadi Rezaee27-May-02 6:36 
GeneralRe: Subject: Flickering (A problem for EVER) Pin
Hadi Rezaee27-May-02 7:59
Hadi Rezaee27-May-02 7:59 
GeneralRe: Subject: Flickering (A problem for EVER) Pin
Alan Chambers27-May-02 6:06
Alan Chambers27-May-02 6:06 
GeneralRe: Subject: Flickering (A problem for EVER) Pin
Hadi Rezaee27-May-02 6:35
Hadi Rezaee27-May-02 6:35 
GeneralRe: Subject: Flickering (A problem for EVER) Pin
Hadi Rezaee27-May-02 8:01
Hadi Rezaee27-May-02 8:01 
GeneralRe: Subject: Flickering (A problem for EVER) Pin
Alan Chambers27-May-02 9:20
Alan Chambers27-May-02 9:20 
GeneralRe: Subject: Flickering (A problem for EVER) Pin
Hadi Rezaee27-May-02 9:26
Hadi Rezaee27-May-02 9:26 
GeneralRe: Subject: Flickering (A problem for EVER) Pin
Alan Chambers27-May-02 10:02
Alan Chambers27-May-02 10:02 
GeneralCalling Windiff within my program Pin
Gilfrog27-May-02 5:00
Gilfrog27-May-02 5:00 
GeneralRe: Calling Windiff within my program Pin
Martin Ziacek27-May-02 5:54
Martin Ziacek27-May-02 5:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.