abhimanipal 91 Master Poster

Just a small addition to the above post.
When ever you declare arrays dynamically you must

int main()
{
        int *arr =(int *)malloc(sizeof(int)*10);

        if(!arr){
                // Check if you did get the memory you asked for
                printf("No memory. Terminating program\n");
                exit(1);
        }
        else{
                printf("Sufficient memory found\n");
        }

        // Do operation on the array here

        free(arr);                     // Free the memory that was given to you after you are done using it 
        return 0;
}
abhimanipal 91 Master Poster

What exactly is your problem ?
As the way I see there are many issues with this program. That being said I appreciate the fact that you attempted to work on this problem instead of simply posting "give me the code"
Here check out this link
It is very helpful guide on how to write code for basic binary tree problems

abhimanipal 91 Master Poster

I am not so sure if that was the only reason for your problem . Try running this piece of code

int main()
{
    char *arr = "ls -l";
    char *pch = NULL;
    
    printf("%s\n",arr);
    pch = strtok(arr," ");
    printf("%s\n",pch);

    return 0;
}

This will give you a seg fault. The reason being when you write
char *arr the memory for this is in the code segment of the program. You are not allowed to modify anything that is written in the code segement
When you issue the strtok command, you are telling the program to replace each instance of " " with '\0' or in other words you are modifying data written in the code segment.
The system does not like this and hence crashes on you

abhimanipal 91 Master Poster

This seems like an interesting question so I will ad myself to this discussion

@Banfa can you explain this concept with a bit of more detail ?

abhimanipal 91 Master Poster

i want pascal triangle code i am a beginner doing my m.c.a

If I am not wrong MCA is a post graduate degree right ? If it is indeed a post graduate degree then its high time you started writing your own code

abhimanipal 91 Master Poster

Bus error is usually because you have tried to access some memory that does not belong to you

- You have int arr[10] and you try to access the arr[10]

Your best bet is to use printf's to try to narrow down the problem

abhimanipal 91 Master Poster

Well I dont think strtok will give you that
What you can do is something like this

Use strtok to find the next token
Use strlen to find the length of this token. Let this be l1
Now your string of interest is from l1 to end of the original string

abhimanipal 91 Master Poster

If the number of groups will always be the same then use the nested loops logic suggested by Adak

abhimanipal 91 Master Poster

Do you know what is a terminal ?
Do you know how to open a file via the terminal ?- pico ? vi ?

abhimanipal 91 Master Poster

Why do you want to open the num file when both the number and name are present in the numAndName file ?

abhimanipal 91 Master Poster

@gudads
If this is your first program I suggest you ditch X-Code and work on the terminal

abhimanipal 91 Master Poster

@SanJuanWolf
Who decided the number of groups ?

@Adak
Quick question. How do you plan to implement nested loops when the number of groups is a variable

I have a dirty solution which may work in this scenario but I am hoping Adak can make that unnecessary

abhimanipal 91 Master Poster

How is this related to C programming ?

abhimanipal 91 Master Poster

What is the value of result ?
Are you sure new_fd is initialized correctly ?

abhimanipal 91 Master Poster

Quick question are you storing the linked list globally ?

abhimanipal 91 Master Poster

Maybe you google for them .....
Its not that hard

abhimanipal 91 Master Poster

i think u already know abt it..
i think u expect the following answer..
the regular expressions such as 0*1* are all difficult to compute using fsm.
turing machine discovered by alan turing. turing machine is an abstract machine tat is discovered in 1940s(not sure) before the invention of computers.it can perform all the operations of todays computer.it has many advantage over fsm.
it have infinite tape moving bidirectionally.
for further details see
thoery of computation lectures @youtube
or
coderisland channel@youtube

I know what a Turing machine is
The OP want to know how exactly would you make a c program to simulate a Turing machine

abhimanipal 91 Master Poster

So what is your problem then ?
Ad task is similar to add a node in the linked list
Delete task is delete a node from the linked list
Print task list is print all the node is the linked list

abhimanipal 91 Master Poster

I think the problem is that you are trying to send images rather than being a N/W problem.

Maybe this will be of help

abhimanipal 91 Master Poster

Have you worked with a linked list ? I think all of your functions are some of the most basic operations on a linked list

abhimanipal 91 Master Poster

I can help you a little bit. My changes are in red

show you simple example of pipe

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <wait.h>

int main()
{
    pid_t pid;
    int pipe_fd[2];
    if ( pipe(pipe_fd) == -1 )
    {
        perror("Pipe create error");
        exit(1);
    }

    if ( (pid = fork()) == -1 )
    {
        perror("Fork create error");
        exit(1);
    }

    if ( pid == 0 )
    {
        close(pipe_fd[0]);                   /* close open fd of pipe */
        
        /* write fd of pipe */
        /* Connect stdout to your pipe */
        /* Then execute the grep function */  
        if ( write(pipe_fd[1], "this is pipe", 128) == -1 )
        {
            perror("Write Error");
            exit(1);
        }
        exit(0);
    }

    if ( pid > 0 )
    {
        waitpid(pid, NULL, 0);
        close(pipe_fd[1]);                   /* close write fd of pipe */      
        char buffer[14] = { 0 };
        
        /* read fd of pipe */
        /* Now execute the sort command. But I dont know how will you tell the system that you want to sort the contents in buffer */

        if ( read(pipe_fd[0], buffer, 128) == -1 )
        {
            perror("Read error");
            exit(1);
        }
        printf("Read string is : %s", buffer);
        exit(0);
    }
}
abhimanipal 91 Master Poster

Are you having a problem only with image data or even with simple data as well ?
The RST flag is usually raised when a host receives a packet which does not belong to the current connection.

abhimanipal 91 Master Poster

you can use turing machine concept than finite machines to this..

What exactly do you mean ?

abhimanipal 91 Master Poster

Turbo C is really outdated maybe you want to consider switching to a newer editor

abhimanipal 91 Master Poster

I think your problem is that your screen is getting cleared . Try removing the clrscr() commands for options 2, 3.

abhimanipal 91 Master Poster

No what I meant was... You are any way going to spawn multiple thread so what is the problem is one of the threads wait for the user input (in other words why exactly do you not want to use fgets)

abhimanipal 91 Master Poster

I am sorry can you explain a bit more ....
What is the exact problem that you are facing ? This is the O/P that I got after running your code

$ ./test


[1] Stack
[2] Queue
[3] Exit

Enter your choice: 1


[1] Push an item
[2] Pop an item
[3] Display the items
[4] Exit

Enter your choice: 1

Enter a number to be saved in the Stack List: 10

is pushed in the Stack List.

[1] Push an item
[2] Pop an item
[3] Display the items
[4] Exit

Enter your choice: 1

Enter a number to be saved in the Stack List: 20

is pushed in the Stack List.

[1] Push an item
[2] Pop an item
[3] Display the items
[4] Exit

Enter your choice: 3

Stack List contains: Top->20->10->NULL

[1] Push an item
[2] Pop an item
[3] Display the items
[4] Exit

Enter your choice: 2

20 has been popped out.

[1] Push an item
[2] Pop an item
[3] Display the items
[4] Exit

Enter your choice: 2

10 has been popped out.

[1] Push an item
[2] Pop an item
[3] Display the items
[4] Exit

Enter your choice: 2

The stack list is empty.

$

abhimanipal 91 Master Poster

If you are planning for multi threading then why not let a thread wait for user input ?

abhimanipal 91 Master Poster

Check out this. This already has some sample code with it

this for a more conceptual explanation

abhimanipal 91 Master Poster

Are you using Turbo - C ?

abhimanipal 91 Master Poster

1. Remove the dependency on conio.h
2. void main should be int main
3. No need for getch()/ clrscr
4. Get rid of scanf

abhimanipal 91 Master Poster

By the way how is the book ?
As in what topics does the book cover ?

abhimanipal 91 Master Poster

This is my O/P on a mac machine

~$ ./test
initial file handle :: 0
child read :: abcdefghij
child file handle :: 11
parent file handle :: 28
parent read ::
end file handle :: 28
~$

Maybe some one could shed some more light on this matter

abhimanipal 91 Master Poster

Please elaborate more
What exactly do you want to know ?

abhimanipal 91 Master Poster

Also even if you have a very basic knowledge of C and math, calculating the average should be easy

abhimanipal 91 Master Poster

Also the OP wants to know the names of the header files not the count .....

If the objective of OP is to prevent including the same header file many times then check out this link

abhimanipal 91 Master Poster
abhimanipal 91 Master Poster

If you are interested in fixing your code I would start of by getting rid of the list data structure ... It just adds complexity

abhimanipal 91 Master Poster

You have declared the name as a float variable. Change it to a char array

Also the correct way to accept a string via scanf statement is
scanf("%s",input);

PS: Using scanf to take user i/p is a bad idea. It usually leads to a wide varieties of problems. Use fgets for taking i/p from the user

abhimanipal 91 Master Poster

Well to start with try to convert an integer to string . While there are inbuilt functions you can use for this I would encourage you write your own. It will be a good experience if you are new to programming
Post your doubts/ questions here

abhimanipal 91 Master Poster

lol....

abhimanipal 91 Master Poster

Can you describe the problem in more detail ?
Simple saying that the O/P is wrong is not sufficient .
put some printf's in your code and see how the control is flowing

Of the top of my head I see you have used the pointer *tmp but there is no memory allotted for it

PS Use code tags when you are posting code

abhimanipal 91 Master Poster

Also the return type of your printDetails() function is int but you are not returning anything from that function. Either make the return type of that function void of return an int value from that function

abhimanipal 91 Master Poster

Run the code despite the warning . What O/P did you get ?

I ran this code

int main()
{
        int x=5;

        switch(x >0)
        {
                case 1: printf("In case 1\n");
                        break;
                case 0: printf("In case 0\n");
                        break;
        }

        return 0;
}

and this was my O/P


$ ./test
In case 1
$

abhimanipal 91 Master Poster

Why is the array not declared ?

abhimanipal 91 Master Poster

How about giving us some idea of which part of the code is not working ...
You know some thing of the sort this should be the expected O/P and this is what I am getting ......

abhimanipal 91 Master Poster

and i want to know is it legal to have one side pointer arithmetic and on one side a int variable

I guess what you are asking is, is it legal to have a pointer and an integer value in the same arithmetic expression

You can have something of this sort

int x[]={1,2,3,4,5};
int *p=x;

printf("%d\n",*p);    // Prints out 1
p=p+1;
printf("%d\n",*p);    // Prints out 2
abhimanipal 91 Master Poster

Quick question ... When you open a file why dont you check if the file has actually been opened or not ?

abhimanipal 91 Master Poster

@daredevil786

The most simplest explanation for you code

y= ptr- x;
= (x+4)- x;
= 4

On a more serious note, have you studied pointer arithmetic ?

abhimanipal 91 Master Poster

There are a couple of things

If you have

int x=[1,2,3,4,5];
printf("%u\n",x);        // Address of the first element of the arry
printf("%d\n",*x);       // Value of the element at the address x ie the first element of the array

So if you write the statement

y = ptr - *x;
// ptr contains an address, but *x contains a value

Also I think you made a typo in the line

int *ptr, y;
// Should have been
int *ptr, *y;