Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. what is fprintf equivalent in qt ?
Qt 6.11 is out! See what's new in the release blog

what is fprintf equivalent in qt ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 469 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by
    #1

    please provide suggestion to convert below c code into qt equivalent code

       FILE *fp;
            int errnum,i=0;
    
            char ra[50],text[4];
    
                fp = fopen(SOURCE_FILE,"r");
    
                    if( fp == NULL)
                    {
                        printf("the file is now opened.\n");
    
                        errnum = errno;
    
                        fprintf(stderr, "Value of errno: %d\n", errno);
    
                        perror("Error printed by perror");
    
                        fprintf(stderr, "Error opening file: %s\n", strerror( errnum ));
    
                    }
                    else
                    {
                        printf("file is now opened\n");
    
                        /*
                        while( fgets(ra, 50, fp) != NULL)
                        {
                               printf("%s",ra);
                        }
                        */
    
                       fseek(fp, -543, SEEK_END);
                        //fflush(ra);
                       fgets ( ra, 50, fp );
                        printf("After SEEK_END to -505 :\n%s\n", ra);
                        printf("sizeof(ra) %lu\n",sizeof(ra));
    
                        for(i;i<10;i++)
                        {
                        printf("%d %c  \n",i,ra[i]);
                        }
    
                       text[0] = ra[1];
                       text[1] = ra[4];
                       text[2] = ra[7];
                       text[3] = '\0';
    
    
                        printf("text ------> %s\n",text);
                        if( fclose(fp) == 0)
                        {
                        printf("data is read successfully \n");
                        printf("the file is now closed\n\n");
                        }
    
                        printf("Data successfully read from file.c \n");
                        printf("the file is now closed.\n");
                    }
    
    KroMignonK 1 Reply Last reply
    0
    • Q Qt embedded developer

      please provide suggestion to convert below c code into qt equivalent code

         FILE *fp;
              int errnum,i=0;
      
              char ra[50],text[4];
      
                  fp = fopen(SOURCE_FILE,"r");
      
                      if( fp == NULL)
                      {
                          printf("the file is now opened.\n");
      
                          errnum = errno;
      
                          fprintf(stderr, "Value of errno: %d\n", errno);
      
                          perror("Error printed by perror");
      
                          fprintf(stderr, "Error opening file: %s\n", strerror( errnum ));
      
                      }
                      else
                      {
                          printf("file is now opened\n");
      
                          /*
                          while( fgets(ra, 50, fp) != NULL)
                          {
                                 printf("%s",ra);
                          }
                          */
      
                         fseek(fp, -543, SEEK_END);
                          //fflush(ra);
                         fgets ( ra, 50, fp );
                          printf("After SEEK_END to -505 :\n%s\n", ra);
                          printf("sizeof(ra) %lu\n",sizeof(ra));
      
                          for(i;i<10;i++)
                          {
                          printf("%d %c  \n",i,ra[i]);
                          }
      
                         text[0] = ra[1];
                         text[1] = ra[4];
                         text[2] = ra[7];
                         text[3] = '\0';
      
      
                          printf("text ------> %s\n",text);
                          if( fclose(fp) == 0)
                          {
                          printf("data is read successfully \n");
                          printf("the file is now closed\n\n");
                          }
      
                          printf("Data successfully read from file.c \n");
                          printf("the file is now closed.\n");
                      }
      
      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @Qt-embedded-developer said in what is fprintf equivalent in qt ?:

      please provide suggestion to convert below c code into qt equivalent code

      Take a look at QFile, QTextStream and QDataStream:
      You could start here: https://doc.qt.io/qt-5/qfile.html#details

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      6

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved