Vita pr0xyRandom Homebrew: Vita pr0xy
A network proxy by SKFU, especially useful for the PS Vita. Features: Proxy especially for PS V [...]

--> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Forum rules
Any post not directly related to programming will be moderated.
Do not request people to code something for you.
Avoid posting messages that do not bring anything to the conversation. We want the threads in this subforum to stay focused.

Re: --> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Postby m0skit0 » Thu Dec 15, 2011 12:44 pm

Advertising
varun wrote:I need it because,I. Don't have knowledge of makefile and also,it

Then, as I said, learn to program first. Make and Makefiles are quasi-standard for C compiling. Also, as I said many times, learning programming on Windows is almost useless for programming on other systems other than Windows, because Windows does stuff in a non-standard way.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
User avatar
m0skit0
Guru
 
Posts: 4800
Joined: Mon Sep 27, 2010 6:01 pm

Re: --> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Postby noname120 » Fri Dec 16, 2011 2:52 pm

Advertising
+1

Those who say "learn to program on Windows first" are stupid.
I'm evil :twisted:
Image
noname120
 
Posts: 667
Joined: Thu Oct 07, 2010 4:29 pm

Re: --> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Postby varun » Sat Dec 17, 2011 12:00 pm

is there any way i can see my errors other than a screenshot before it exits
a.jpg
a.jpg (103.79 KiB) Viewed 1052 times


anyway.. i dont get it because i have declared question and its a structure not an function

source
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspcallbacks.h>


PSP_MODULE_INFO("Quiz",0,1,1);


   struct question
   { 
                                          // Declare question struct type
   char ques[150];                             // Declare member types
   char op1[100],op2[100],op3[100],op4[100];
   int true_op;
  }
family_question;                               // Define object of type question

char revert(int a)
{
   if(a==1) return 'T';
   else if(a==2) return 'S';
   else if(a==3) return 'X';
   else if(a==4) return 'O';
   else return 'x';
}

int main() {
      pspDebugScreenInit();
      pspDebugScreenClear();
      SetupCallbacks();
      printf("Welcome to my quiz\n");
      const int a = 10;
      question q[a];
   
   
      {
      int m,n;
      for(m=0;m<10;m++)
         {
         for(n = 0;n<150;n++) q[m].ques[n] = '\0';
         for(n = 0;n<50;n++) q[m].op1[n] = '\0';
         for(n = 0;n<50;n++) q[m].op2[n] = '\0';
         for(n = 0;n<50;n++) q[m].op3[n] = '\0';
         for(n = 0;n<50;n++) q[m].op4[n] = '\0';
         }

      }
   
   strcat(q[0].ques ,"By which of these nicknames is Nagpur also known as?");
   strcat(q[0].op1 , "Diamond City");
   strcat(q[0].op2 , "Orange City");
   strcat(q[0].op3 , "Pink City");
   strcat(q[0].op4 , "City of Lakes");
   q[0].true_op = 2;
 
   strcat(q[1].ques , "Which pieces are maximum in number at the start of a chess game");
   strcat(q[1].op1 , "Rook");
   strcat(q[1].op2 , "Knight");
   strcat(q[1].op3 , "Pawn");
   strcat(q[1].op4 , "Bishop");
   q[1].true_op = 3;
   
   strcat(q[2].ques , "What was the name of India’s first unmanned lunar spacecraft launched in October 2008?");
   strcat(q[2].op1 , "Chandravahaan 1");
   strcat(q[2].op2 , "Chandrayaan 1");
   strcat(q[2].op3 , "Chandravimaan 1");
   strcat(q[2].op4 , "Chadrakhoj 1");
   q[2].true_op = 2;

   strcat(q[3].ques , "Grand Central Terminal, Park Avenue, New York is the world's");
   strcat(q[3].op1 , "largest railway station");
   strcat(q[3].op2 , "highest railway station");
   strcat(q[3].op3 , "longest railway station");
   strcat(q[3].op4 , "None of the above");
   q[3].true_op = 1;

   strcat(q[4].ques , "Entomology is the science that studies");
   strcat(q[4].op1 , "Behavior of human beings");
   strcat(q[4].op2 , "Insects");
   strcat(q[4].op3 , "The origin and history of technical and scientific terms");
   strcat(q[4].op4 , "The formation of rocks");
   q[4].true_op = 2;

   strcat(q[5].ques , "Eritrea, which became the 182nd member of the UN in 1993, is in the continent o");
   strcat(q[5].op1 , "Asia");
   strcat(q[5].op2 , "Africa");
   strcat(q[5].op3 , "Europe");
   strcat(q[5].op4 , "Australia");
   q[5].true_op = 2;

   strcat(q[6].ques , "Garampani sanctuary is located at");
   strcat(q[6].op1 , "Junagarh, Gujarat");
   strcat(q[6].op2 , "Diphu, Assam");
   strcat(q[6].op3 , "Kohima, Nagaland");
   strcat(q[6].op4 , "Gangtok, Sikkim");
   q[6].true_op = 2;

   strcat(q[7].ques , "Hitler party which came into power in 1933 is known as");
   strcat(q[7].op1 , "Labour Party");
   strcat(q[7].op2 , "Nazi Party");
   strcat(q[7].op3 , "Ku-Klux-Klan");
   strcat(q[7].op4 , "Democratic Party");
   q[7].true_op = 2;

   strcat(q[8].ques , "For which of the following disciplines is Nobel Prize awarded?");
   strcat(q[8].op1 , "Physics and Chemistry");
   strcat(q[8].op2 , "Physiology or Medicine");
   strcat(q[8].op3 , "Literature, Peace and Economics");
   strcat(q[8].op4 , "All of the above");
   q[8].true_op = 4;

   strcat(q[9].ques , "FFC stands for");
   strcat(q[9].op1 , "Foreign Finance Corporation");
   strcat(q[9].op2 , "Film Finance Corporation");
   strcat(q[9].op3 , "Federation of Football Council");
   strcat(q[9].op4 , "None of the above");
   q[9].true_op = 2;
   
   

   pspDebugScreenPrintf(("The rules of the quiz are as follows-\n");
   pspDebugScreenPrintf(("*For each true answer you will get 3 points.\n");
   pspDebugScreenPrintf(("*For each wrong answer you will loose 1 point.\n");
   pspDebugScreenPrintf(("*You have to answer question by pressing a/A,b/B,c/C,d/D.\n");
   
   pspDebugScreenPrintf(("*You can quit the game any time by entering Start as your choice.\n");
   pspDebugScreenPrintf(("*You can skip the question by entering Select as your choice.\n");
   
   
   pspDebugScreenSetXY(0, 0);
   sceCtrlReadBufferPositive(&pad, 1);
   
   
   int x ,choice,i,,t=0,n=0;
   int points=0;
   char user;
   for(i=0;i<10;i++) flag[i]= 0;
      
   for (x = 0; x < a; x++)
   
         
         pspDebugScreenPrintf( "\n\n%s\n" ,q[x].ques);
         pspDebugScreenPrintf( "Your options are - \n");
         pspDebugScreenPrintf( "T(triangle))%s\n",q[x].op1 );
         pspDebugScreenPrintf( "S(square))%s\n",q[x].op1 );
         pspDebugScreenPrintf( "X)%s\n",q[x].op1 );
         pspDebugScreenPrintf( "O)%s\n",q[x].op1 );
         
         
ask:         
         pspDebugScreenPrintf( "\nEnter your choice\n");
         

         for(i=0;i!=1;)
            {
            
            if (pad.Buttons & PSP_CTRL_CIRCLE)
            choice 4;
            else if (pad.Buttons & PSP_CTRL_CROSS)
            choice 3;
            else if (pad.Buttons & PSP_CTRL_SQUARE)
            choice 2;
            else if (pad.Buttons & PSP_CTRL_TRIANGLE)
            choice 1;
            else if (pad.Buttons & PSP_CTRL_START)
            choice 5;
            else if (pad.Buttons & PSP_CTRL_SELECT)
            choice 6;
            
            

         

         if (choice == 5)//For quiting purpose
         {   pspDebugScreenPrintf("Are You Sure that you want to quit?(X for yes)\n");
         
            if (pad.Buttons & PSP_CTRL_START) break;
            else goto ask;
         }

         if (choice == 6)//For skipping purpose
         {
            pspDebugScreenPrintf("Are You Sure that you want to skip the question?(y/Y)\n";
            if (pad.Buttons & PSP_CTRL_SELECT) goto skip;
            else goto ask;
         }
            
         if (choice == q[x].true_op)
         {
            pspDebugScreenPrintf("True...+3 points\n");
            points += 3;
            t++;
            
         }

         else
         {
            pspDebugScreenPrintf( "Wrong Answer..!!!, you get -1 points\n");
            points -= 1;
            pspDebugScreenPrintf("the correcsst answer was...%s\n",revert(q[x].true_op));
         }
         n++;
skip:;
      }
      pspDebugScreenClear();

      pspDebugScreenPrintf("\n\n\n\nQuiz finished \n");
      pspDebugScreenPrintf("Number of questions you attemted = %d\n",n);
      pspDebugScreenPrintf("Number of correct quetions = %d\n",t);
      
   
   sceKernelSleepThread();
     return 0;
}   

User avatar
varun
Banned
 
Posts: 1059
Joined: Thu Jan 27, 2011 12:32 pm
Location: Mars

Re: --> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Postby snailface » Sat Dec 17, 2011 3:17 pm

Alright, I fixed your errors until it will actually compile. There will likely be more problems at runtime, but at least you are on track now. ;)
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspcallbacks.h>
#include <pspctrl.h>

PSP_MODULE_INFO("Quiz",0,1,1);

   struct question
   {
                                          // Declare question struct type
   char ques[150];                             // Declare member types
   char op1[100],op2[100],op3[100],op4[100];
   int true_op;
  }; 

                       // Define object of type question

char revert(int a)
{
   if(a==1) return 'T';
   else if(a==2) return 'S';
   else if(a==3) return 'X';
   else if(a==4) return 'O';
   else return 'x';
}

int main() {
      SceCtrlData pad;
      pspDebugScreenInit();
      pspDebugScreenClear();
      SetupCallbacks();
      printf("Welcome to my quiz\n");
    
     int flag[10];
      int a=10;
      struct question q[a];
      int m,n;
     
    
     for(m=0;m<10;m++)
         {
         for(n = 0;n<150;n++) q[m].ques[n] = '\0';
         for(n = 0;n<50;n++) q[m].op1[n] = '\0';
         for(n = 0;n<50;n++) q[m].op2[n] = '\0';
         for(n = 0;n<50;n++) q[m].op3[n] = '\0';
         for(n = 0;n<50;n++) q[m].op4[n] = '\0';
         }

     
   
   strcat(q[0].ques ,"By which of these nicknames is Nagpur also known as?");
   strcat(q[0].op1 , "Diamond City");
   strcat(q[0].op2 , "Orange City");
   strcat(q[0].op3 , "Pink City");
   strcat(q[0].op4 , "City of Lakes");
   q[0].true_op = 2;

   strcat(q[1].ques , "Which pieces are maximum in number at the start of a chess game");
   strcat(q[1].op1 , "Rook");
   strcat(q[1].op2 , "Knight");
   strcat(q[1].op3 , "Pawn");
   strcat(q[1].op4 , "Bishop");
   q[1].true_op = 3;
   
   strcat(q[2].ques , "What was the name of India’s first unmanned lunar spacecraft launched in October 2008?");
   strcat(q[2].op1 , "Chandravahaan 1");
   strcat(q[2].op2 , "Chandrayaan 1");
   strcat(q[2].op3 , "Chandravimaan 1");
   strcat(q[2].op4 , "Chadrakhoj 1");
   q[2].true_op = 2;

   strcat(q[3].ques , "Grand Central Terminal, Park Avenue, New York is the world's");
   strcat(q[3].op1 , "largest railway station");
   strcat(q[3].op2 , "highest railway station");
   strcat(q[3].op3 , "longest railway station");
   strcat(q[3].op4 , "None of the above");
   q[3].true_op = 1;

   strcat(q[4].ques , "Entomology is the science that studies");
   strcat(q[4].op1 , "Behavior of human beings");
   strcat(q[4].op2 , "Insects");
   strcat(q[4].op3 , "The origin and history of technical and scientific terms");
   strcat(q[4].op4 , "The formation of rocks");
   q[4].true_op = 2;

   strcat(q[5].ques , "Eritrea, which became the 182nd member of the UN in 1993, is in the continent o");
   strcat(q[5].op1 , "Asia");
   strcat(q[5].op2 , "Africa");
   strcat(q[5].op3 , "Europe");
   strcat(q[5].op4 , "Australia");
   q[5].true_op = 2;

   strcat(q[6].ques , "Garampani sanctuary is located at");
   strcat(q[6].op1 , "Junagarh, Gujarat");
   strcat(q[6].op2 , "Diphu, Assam");
   strcat(q[6].op3 , "Kohima, Nagaland");
   strcat(q[6].op4 , "Gangtok, Sikkim");
   q[6].true_op = 2;

   strcat(q[7].ques , "Hitler party which came into power in 1933 is known as");
   strcat(q[7].op1 , "Labour Party");
   strcat(q[7].op2 , "Nazi Party");
   strcat(q[7].op3 , "Ku-Klux-Klan");
   strcat(q[7].op4 , "Democratic Party");
   q[7].true_op = 2;

   strcat(q[8].ques , "For which of the following disciplines is Nobel Prize awarded?");
   strcat(q[8].op1 , "Physics and Chemistry");
   strcat(q[8].op2 , "Physiology or Medicine");
   strcat(q[8].op3 , "Literature, Peace and Economics");
   strcat(q[8].op4 , "All of the above");
   q[8].true_op = 4;

   strcat(q[9].ques , "FFC stands for");
   strcat(q[9].op1 , "Foreign Finance Corporation");
   strcat(q[9].op2 , "Film Finance Corporation");
   strcat(q[9].op3 , "Federation of Football Council");
   strcat(q[9].op4 , "None of the above");
   q[9].true_op = 2;
   
   

   pspDebugScreenPrintf("The rules of the quiz are as follows-\n");
   pspDebugScreenPrintf("*For each true answer you will get 3 points.\n");
   pspDebugScreenPrintf("*For each wrong answer you will loose 1 point.\n");
   pspDebugScreenPrintf("*You have to answer question by pressing a/A,b/B,c/C,d/D.\n");
   
   pspDebugScreenPrintf("*You can quit the game any time by entering Start as your choice.\n");
   pspDebugScreenPrintf("*You can skip the question by entering Select as your choice.\n");
   
   
   pspDebugScreenSetXY(0, 0);
   sceCtrlReadBufferPositive(&pad, 1);
   
   
   
   int x ,choice=0,i,t=0;
   int points=0;
   char user;
   for(i=0;i<10;i++) flag[i]= 0;
     
   for (x = 0; x < a; x++){
   
         
         pspDebugScreenPrintf( "\n\n%s\n" ,q[x].ques);
         pspDebugScreenPrintf( "Your options are - \n");
         pspDebugScreenPrintf( "T(triangle))%s\n",q[x].op1 );
         pspDebugScreenPrintf( "S(square))%s\n",q[x].op1 );
         pspDebugScreenPrintf( "X)%s\n",q[x].op1 );
         pspDebugScreenPrintf( "O)%s\n",q[x].op1 );
         
         
ask:         
         pspDebugScreenPrintf( "\nEnter your choice\n");
         

         for(i=0;i!=1;)
            {
           
            if (pad.Buttons & PSP_CTRL_CIRCLE)
            choice=4;
            else if (pad.Buttons & PSP_CTRL_CROSS)
            choice=3;
            else if (pad.Buttons & PSP_CTRL_SQUARE)
            choice=2;
            else if (pad.Buttons & PSP_CTRL_TRIANGLE)
            choice=1;
            else if (pad.Buttons & PSP_CTRL_START)
            choice=5;
            else if(pad.Buttons & PSP_CTRL_SELECT)
            choice=6;
           
           

         

         if (choice == 5)//For quiting purpose
         {   pspDebugScreenPrintf("Are You Sure that you want to quit?(X for yes)\n");
         
            if (pad.Buttons & PSP_CTRL_START) break;
            else goto ask;
         }

         if (choice == 6)//For skipping purpose
         {
            pspDebugScreenPrintf("Are You Sure that you want to skip the question?(y/Y)\n");
            if (pad.Buttons & PSP_CTRL_SELECT) goto skip;
            else goto ask;
         }
           
         if (choice == q[x].true_op)
         {
            pspDebugScreenPrintf("True...+3 points\n");
            points += 3;
            t++;
           
         }

         else
         {
            pspDebugScreenPrintf( "Wrong Answer..!!!, you get -1 points\n");
            points -= 1;
            pspDebugScreenPrintf("the correcsst answer was...%s\n",revert(q[x].true_op));
         }
         n++;
      }
      skip:;
      }
      pspDebugScreenClear();

      pspDebugScreenPrintf("\n\n\n\nQuiz finished \n");
      pspDebugScreenPrintf("Number of questions you attemted = %d\n",n);
      pspDebugScreenPrintf("Number of correct quetions = %d\n",t);
     
   
   sceKernelSleepThread();
     return 0;
}   
Image
snailface
 
Posts: 100
Joined: Tue May 24, 2011 8:02 pm

Re: --> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Postby varun » Sun Dec 18, 2011 10:42 am

thank you very much sir,it worked.please tell is there any way way i can track them them before it exits
User avatar
varun
Banned
 
Posts: 1059
Joined: Thu Jan 27, 2011 12:32 pm
Location: Mars

Re: --> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Postby snailface » Sun Dec 18, 2011 1:32 pm

varun wrote:thank you very much sir,it worked.please tell is there any way way i can track them them before it exits

Frankly, that program needed to be rewritten. :lol: It was overly complex, you didn't need any of those structs, strcats, and arrays. Pretty much loops, if statements, and printf are all you need.

I've given you a head start with the rewrite, you just have to finish questions 3-10.

Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspcallbacks.h>
#include <pspctrl.h>
#define printf pspDebugScreenPrintf  //shorten that print function -- easy does it :p
PSP_MODULE_INFO("Quiz",0,1,1);

choice=0;       //less variables, less headaches ^_^
points=0;
SceCtrlData pad; 

/// FUNCTIONS
/////////////////////////

padinput() //checks for user input
{
            choice=0;//keeps choice from repeating to next question
          sceCtrlReadBufferPositive(&pad, 1);
         
            if(pad.Buttons & PSP_CTRL_CIRCLE)choice=4;
       
            if(pad.Buttons & PSP_CTRL_CROSS)choice=3;
           
            if(pad.Buttons & PSP_CTRL_SQUARE)choice=2;
           
            if(pad.Buttons & PSP_CTRL_TRIANGLE)choice=1;
           
            if(pad.Buttons & PSP_CTRL_START)choice=5;
           
            if(pad.Buttons & PSP_CTRL_SELECT)choice=6;
         
         
};

scoring(int correct) //provides results from question and adds up score 'correct' is the correct choice
{                    //(add it in the function itself, you'll see below)
            if(choice==6)printf("Skipped!!");
         
         if(choice==correct){printf("True...+3 points\n");
            points+=3;}
     
            if(choice!=correct&&choice!=6){
            printf( "Wrong Answer..!!!, you get -1 points\n");
            points--; //subtracts 1 point--shorthand for what you had before
            printf("the correct answer was...\n");}
};

//main-------------------------------------------------------------------------------------------------------
int main() {
while(1){   //this loop keeps the entire program running until user wants to quit (start button)

     
      pspDebugScreenInit();
      pspDebugScreenClear();
      SetupCallbacks();
    
    
      points=0;
     

    
   printf("Welcome to my quiz\n\n");
   printf("The rules of the quiz are as follows-\n");
   printf("*For each true answer you will get 3 points.\n");
   printf("*For each wrong answer you will loose 1 point.\n");
   printf("*You have to answer question by pressing a/A,b/B,c/C,d/D.\n");
   printf("*You can quit the game any time by entering Start as your choice.\n");
   printf("*You can skip the question by entering Select as your choice.\n\n\n");
     
   
   
   
   //question 1
   printf("By which of these nicknames is Nagpur also known as?\n\n");
   printf("TRIANG Diamond City\n");
   printf("SQUARE Orange City\n");
   printf("CROSS  Pink City\n");
   printf("CIRCLE City of Lakes\n\n");
   printf("  START  Quit\n");
   printf("  SELECT Skip\n");
   
   while(1){  //small loop to wait and check for user response
   padinput();
   if(choice==5)sceKernelExitGame();
   if(choice!=0)break;
   }
      scoring(2); //calculate and print question result -- choice '2' is correct
      sleep(2);
      pspDebugScreenClear();
   
   
   
   //question 2
   printf("Which pieces are maximum in number at the start of a chess game\n\n");
   printf("TRIANG Rook\n");
   printf("SQUARE Knight\n");
   printf("CROSS  Pawn\n");
   printf("CIRCLE Bishop\n\n");
   printf("  START  Quit\n");
   printf("  SELECT Skip\n");
   
   while(1){
   padinput();
   if(choice==5)sceKernelExitGame();
   if(choice!=0)break;
   }
      scoring(3);
      sleep(2);
      pspDebugScreenClear();
    

      //questions 3-10 -- your job! :O
    
    
    
     printf("\n\n\n\nQuiz finished \n"); //you can finish this part I hope?
      printf("Number of questions you attemted = ?\n");
      printf("Number of correct quetions = ?\n");
     printf("Points = %d",points);
      sleep(4);
   
   
}   
}   
Image
snailface
 
Posts: 100
Joined: Tue May 24, 2011 8:02 pm

Re: --> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Postby varun » Sun Dec 18, 2011 4:27 pm

its cool......i mean defining printf and making padinput and scoring is a cool idea.
about structure part.... i had to do it because in the pc version, my program used to randomly generate the questions...and in psp one i had no idea to randomize things. Its very nice of you to do that :) ..Finally i can program in psp... :lol:

btw..ur awatar reminds me what i got by editing petapon 2 demo's title and ID with notepad..I was on 6.31 frustrated and thought it might work :lol:
User avatar
varun
Banned
 
Posts: 1059
Joined: Thu Jan 27, 2011 12:32 pm
Location: Mars

Re: --> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Postby m0skit0 » Mon Dec 19, 2011 11:21 am

snailface wrote:I fixed your errors until it will actually compile

Please, do not give fish, but teach how to fish. Having you doing his programming means he will never learn programming, and thus he will never stop making threads about the same problem again and again...
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
User avatar
m0skit0
Guru
 
Posts: 4800
Joined: Mon Sep 27, 2010 6:01 pm

Re: --> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Postby daixtr » Fri Dec 23, 2011 7:17 pm

The code snippet above is still incomplete. Must still manually declare SetupCallbacks() etc...And also, <pspcallbacks.h> header file does not exist...
daixtr
 
Posts: 21
Joined: Fri Dec 23, 2011 1:07 pm

Re: --> [PSP PROGRAMMING TUTORIALS IN C!!!] <--

Postby varun » Thu Dec 29, 2011 4:32 pm

we have to download that file if u read the tutorial mr expert(s) :lol: :lol: :lol: :lol: :lol:
User avatar
varun
Banned
 
Posts: 1059
Joined: Thu Jan 27, 2011 12:32 pm
Location: Mars

PreviousNext

Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests

Friends

Coding 'n Cracking - Nymphaea - PS3 Forum - darkforestgroup - daxhordes.org - Tgames - coldbird - gopsp.it - pspstation.org - prometheus - hgoel.info - MakeSmartTV - ps vita