C Programe Help Plz

hans078

Active member
  • Feb 17, 2008
    496
    179
    43
    Colombo
    එලකිරියෙ කවරු හරි C ප්‍රෝග්‍රැමිං දන්නවනම් මට මේ මම අමුනල තියන PDF එකේ තියන ASSIGNMENT එක කරන්න උදව්වක් දෙන්න. මට මේක කර ගන්න තේරෙන්නෙම නෑ. ලොකු උදව්වක්. පුළුවන් කෙනෙක් ඉන්නවන මට කෝඩ් එක ගහන්න උදව් කරනවද? මේක කරන්න සමහර විට fork, signal functions පාවිච්චි කරන්න වේවි.
     

    Attachments

    • Shared Memory Producer.jpg
      Shared Memory Producer.jpg
      80.3 KB · Views: 94
    • Like
    Reactions: udaragun

    amila325

    Well-known member
  • Jul 11, 2006
    9,188
    33
    48
    haffa me ara c wala thiyena fork cn eka neda???... i dnt have time nw.... eth man try ekak dennam guide karanna hari....
     

    Topology

    Member
    Feb 24, 2011
    2,395
    225
    0
    Out of Elakiri.
    මෙන්න පිළිතුර නමුත් මේක මම ලිව්වේ C++ වලින්.
    C
    වලහරවා ගන්න.
    සමාවෙන්න මේච්චරයි මට උදව් කරන්න පුලුවන් මොකද මම වැඩිය C දන්නේ නෑ.
    නමුත් C වලයි C++ වලයි වැඩි වෙනසක් නෑ. Syntax පමණයි
    .
    and NO IOSTREAM in C .!!


    Code:
    #include <iostream>
    
    using namespace std;
    
    
    struct buf{
        int values[100];
    };
    
    int main()
    {
        int i=0;
        int totNum[100];
        struct buf mainBuff;
        
        //ACCEPT THE VALUES
        while(1)
        {
            cout << "press 0 to exit from the loop" << endl;
            cin>>totNum[i];
    
            if(totNum[i] == 0)
            {
                cin.ignore();
                break;
            }
            i++;
        }
        
        //THREAD 1 STORE IN AN ARRAY
        //the values are already in an array
        
        //THREAD 2 SPLIT AND STORE IN THE SHARED BUFFER
        for(int j=0 ;j<i;j++)
        {
            mainBuff.values[j] = totNum[j];
        }
        
        //NOW READ THEM FROM TEH BUFFER AND STORE IN An ARRAY
        int totNumCus[100];
    
        for(int l=0;l<i;l++)
        {
            totNumCus[l] =     mainBuff.values[l];
        }
        
        int tot=0;
        
        //NOW CALCULATE THE TOT AND DISPLAY THE ANSWER
        for(int m=0;m<i;m++)
        {
            tot +=     totNumCus[m];
        }
        
        cout << "the final answer is "  << tot << endl;
    
        cin.get();
    return 0;    
    }
     
    Last edited:

    kasuncs

    Well-known member
  • May 21, 2007
    3,590
    271
    83
    මෙන්න පිළිතුර නමුත් මේක මම ලිව්වේ C++ වලින්.
    C
    වල හරවා ගන්න.
    සමාවෙන්න මේච්චරයි මට උදව් කරන්න පුලුවන් මොකද මම වැඩිය C දන්නේ නෑ.
    නමුත් C වලයි C++ වලයි වැඩි වෙනසක් නෑ. Syntax පමණයි
    .
    and NO IOSTREAM in C .!!


    Code:
    #include <iostream>
    
    using namespace std;
    
    
    struct buf{
        int values[100];
    };
    
    int main()
    {
        int i=0;
        int totNum[100];
        struct buf mainBuff;
        
        //ACCEPT THE VALUES
        while(1)
        {
            cout << "press any character to exit from the loop" << endl;
            cin>>totNum[i];
    
            if(totNum[i] == 0)
            {
                cin.ignore();
                break;
            }
            i++;
        }
        
        //THREAD 1 STORE IN AN ARRAY
        //the values are already in an array
        
        //THREAD 2 SPLIT AND STORE IN THE SHARED BUFFER
        for(int j=0 ;j<i;j++)
        {
            mainBuff.values[j] = totNum[j];
        }
        
        //NOW READ THEM FROM TEH BUFFER AND STORE IN An ARRAY
        int totNumCus[100];
    
        for(int l=0;l<i;l++)
        {
            totNumCus[l] =     mainBuff.values[l];
        }
        
        int tot=0;
        
        //NOW CALCULATE THE TOT AND DISPLAY THE ANSWER
        for(int m=0;m<i;m++)
        {
            tot +=     totNumCus[m];
        }
        
        cout << "the final answer is "  << tot << endl;
    
        cin.get();
    return 0;    
    }

    podi case ekak tiyenawa machan. Meke line by line executaion ekak neda wenne?

    Machan thr_create() use karamu neda?
     

    Topology

    Member
    Feb 24, 2011
    2,395
    225
    0
    Out of Elakiri.
    podi case ekak tiyenawa machan. Meke line by line executaion ekak neda wenne?

    Machan thr_create() use karamu neda?

    ඔතන ඕනවට වඩා අමාරු ඒවා දැම්මම වෙන්නේ අහලා තියෙන කෙනාට තේරුම ගන්න බැරිවෙනවා එතකොට වෙන්නේ මම නිකම් දක්ෂවතාව පෙන්වන එක විතරයි.
     

    ¤--bACarDi--¤

    Well-known member
  • Jan 9, 2009
    12,130
    288
    83
    124.43.xxx.xxx
    මෙන්න පිළිතුර නමුත් මේක මම ලිව්වේ C++ වලින්.
    C
    වලහරවා ගන්න.
    සමාවෙන්න මේච්චරයි මට උදව් කරන්න පුලුවන් මොකද මම වැඩිය C දන්නේ නෑ.
    නමුත් C වලයි C++ වලයි වැඩි වෙනසක් නෑ. Syntax පමණයි
    .
    and NO IOSTREAM in C .!!


    Code:
    #include <iostream>
    
    using namespace std;
    
    
    struct buf{
        int values[100];
    };
    
    int main()
    {
        int i=0;
        int totNum[100];
        struct buf mainBuff;
        
        //ACCEPT THE VALUES
        while(1)
        {
            cout << "press 0 to exit from the loop" << endl;
            cin>>totNum[i];
    
            if(totNum[i] == 0)
            {
                cin.ignore();
                break;
            }
            i++;
        }
        
        //THREAD 1 STORE IN AN ARRAY
        //the values are already in an array
        
        //THREAD 2 SPLIT AND STORE IN THE SHARED BUFFER
        for(int j=0 ;j<i;j++)
        {
            mainBuff.values[j] = totNum[j];
        }
        
        //NOW READ THEM FROM TEH BUFFER AND STORE IN An ARRAY
        int totNumCus[100];
    
        for(int l=0;l<i;l++)
        {
            totNumCus[l] =     mainBuff.values[l];
        }
        
        int tot=0;
        
        //NOW CALCULATE THE TOT AND DISPLAY THE ANSWER
        for(int m=0;m<i;m++)
        {
            tot +=     totNumCus[m];
        }
        
        cout << "the final answer is "  << tot << endl;
    
        cin.get();
    return 0;    
    }



    Threads? where?

    This should hav done using PThreads in C under Unix
     

    Topology

    Member
    Feb 24, 2011
    2,395
    225
    0
    Out of Elakiri.
    Threads? where?

    This should hav done using PThreads in C under Unix

    okay fine. but let me tell you this. if you know how to get this done correctly then why don't you go and give a shot. you are free to do whatever you want. no need to quote rest of answers.. infact you are not the thread starter. obviously this looks like a failed trolling.
     

    ¤--bACarDi--¤

    Well-known member
  • Jan 9, 2009
    12,130
    288
    83
    124.43.xxx.xxx
    okay fine. but let me tell you this. if you know how to get this done correctly then why don't you go and give a shot. you are free to do whatever you want. no need to quote rest of answers.. infact you are not the thread starter. obviously this looks like a failed trolling.


    LOLwut? :lol:

    I saw a WRONG ANSWER & said its wrong cuz ITS WRONG!!! :rofl:

    actually i dnt have an ass pain to do others assignments since i dnt even do mine lolz!! :lol:

    And thread starter is not the only person to say answer is correct or wrong! any idiot can see the question is abt parallel Threads under Unix :D


    and telling abt trolling, this is wht we call trolling LMAO


    ඔතන ඕනවට වඩා අමාරු ඒවා දැම්මම වෙන්නේ අහලා තියෙන කෙනාට තේරුම ගන්න බැරිවෙනවා එතකොට වෙන්නේ මම නිකම් දක්ෂවතාව පෙන්වන එක විතරයි.



    :rofl::rofl::rofl:




    this is a simple thread implementation program in C if u dnt knw!

    should compile with -lpthread

    gcc -oExe1 Exe1.c -lpthreads


    threadsq.jpg




    Now try to do the question :D
     
    Last edited:

    Topology

    Member
    Feb 24, 2011
    2,395
    225
    0
    Out of Elakiri.
    LOLwut? :lol:

    I saw a WRONG ANSWER & said its wrong cuz ITS WRONG!!! :rofl:

    actually i dnt have an ass pain to do others assignments since i dnt even do mine lolz!! :lol:

    And thread starter is not the only person to say answer is correct or wrong! any idiot can see the question is abt parallel Threads under Unix :D


    and telling abt trolling, this is wht we call trolling LMAO






    :rofl::rofl::rofl:




    this is a simple thread implementation program in C if u dnt knw!

    should compile with -lpthread

    gcc -oExe1 Exe1.c -lpthreads


    threadsq.jpg




    Now try to do the question :D


    well that's why at the beginning I said I don't know much about C,
    infact I have done this with C++ and it doesn't even have inbuilt way to implement threads instead entirely relies on the operating system.
    I am a Windows developer and don't know anything about Unix or Linux or Mac. but C's codes are mainly cross platform(and are almost similar as C++) if you implemented according to standard way. that's what I have done so far.
    anyway I could get this done in standard way, at least it may help him to get some idea. finally I don't wanna fight with nooby kiddos who just makes posts but do nothing and put mud on people.
    if you know the way to write this program just go and do that instead poop throughout the thread.
     

    ¤--bACarDi--¤

    Well-known member
  • Jan 9, 2009
    12,130
    288
    83
    124.43.xxx.xxx
    well that's why at the beginning I said I don't know much about C,
    infact I have done this with C++ and it doesn't even have inbuilt way to implement threads instead entirely relies on the operating system.
    I am a Windows developer and don't know anything about Unix or Linux or Mac. but C's codes are mainly cross platform(and are almost similar as C++) if you implemented according to standard way. that's what I have done so far.
    anyway I could get this done in standard way, at least it may help him to get some idea. finally I don't wanna fight with nooby kiddos who just makes posts but do nothing and put mud on people.
    if you know the way to write this program just go and do that instead poop throughout the thread.


    LOL again, as u can see C nither have a inbuilt thread implementation way. thats why pthread.h header file has included at the beginning.

    using this example code, anyone could do that question in their own ways. as i said earlier i dnt do other ppl assignments lolz :lol:


    threadsq.jpg




    මෙන්න පිළිතුර නමුත් මේක මම ලිව්වේ C++ වලින්.




    and lolz i wouldn't write piece of code with bunch of for loops instead of threads & say i did something wht did u do?? huu huu!! and dance on the thread lmao :rofl:
     

    Topology

    Member
    Feb 24, 2011
    2,395
    225
    0
    Out of Elakiri.
    LOL again, as u can see C nither have a inbuilt thread implementation way. thats why pthread.h header file has included at the beginning.

    using this example code, anyone could do that question in their own ways. as i said earlier i dnt do other ppl assignments lolz :lol:


    threadsq.jpg








    and lolz i wouldn't write piece of code with bunch of for loops instead of threads & say i did something wht did u do?? huu huu!! and dance on the thread lmao :rofl:

    okay bye.