Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9129671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:48:08+00:00 2026-06-17T07:48:08+00:00

I wanted to show the whole c program on screen which should be visible

  • 0

I wanted to show the whole c program on screen which should be visible to user.

I used textView but i am getting errors as the code contains special symbols.

for example:

 android:text=" #include <stdio.h>
 int main()
{
int x, y, temp;

printf("Enter the value of x and y\n");
scanf("%d%d", &x, &y);

printf("Before Swapping\nx = %d\ny = %d\n",x,y);

temp = x;
x = y;
y = temp;

printf("After Swapping\nx = %d\ny = %d\n",x,y);

return 0;
 }" />

I also want that the user should be able to scroll the code as the codes may be larger than the example.I am a noob so please suggest me any alternate for the textView to display the code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:48:09+00:00Added an answer on June 17, 2026 at 7:48 am

    Save your C code in a file in assets folder, for example “res/assets/code.c”.

    Write a function that reads the content of a file to a String:

    private String readFileInAssetsDir(String filename) {
        BufferedReader br = null;
        StringBuffer sb = new StringBuffer();
        try {
            br = new BufferedReader(new InputStreamReader(getAssets().open(filename)));
            String line;
            while((line = br.readLine()) != null)
                sb.append(line + "\n");
        } catch(Exception e) {
            // TODO
        }
        return sb.toString();
    }
    

    And now define a WebView (not a TextView) in your layout (the advantages are that you can show any character, and WebView provides zoom and scroll directly):

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1" />
    

    And finally I would enclose all C code in a <pre></pre> tag and then show it inside the WebView widget:

        String plainCode = readFileInAssetsDir("code.c");
        String htmlCode = "<pre>" + plainCode + "</pre>";
        webView.loadDataWithBaseURL("", htmlCode, "text/html", "utf-8", "");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly apologises for the length of code but I wanted to show it all.
After running the program, Logcat shows some errors (picture). But after that program runs
I wanted to show problem with this video. Please watch... I've 2 pages. Second
I wanted to show a vertical drop-down menu on click on a div. Suppose
I have a table view and i wanted to show the phone contacts of
I am validating value entered in textbox against database and wanted to show right
My situation is after login my website I wanted to show how many employees
I wanted to create a link that would show content before showing a direct
I wanted to write a Custom Control that would show a family tree... so
Wanted to know if someone had a suggestion on code or maybe there's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.