problem with ()read and available() funcutions

hai I am new to Arduino programming I want to use read() and available() functions in my code but I am facing some problems
1:-unable to get return value when used available() function
2:-unable to read characters properly when used read() function I,e getting some?symbols instead of characters

here are the output screenshots and code screenshots please help me to find a solution
thanks in advance

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

@OP

Try these commands:

char c = (char)sdcard.read();
Serial.print(c);

even after trying the above commands i got same output on
thank you

Please, post your sketch (the program that you have created in the IDE) in this post page. Follow these steps.

1. Open your file in the IDE.

2. Open a post/reply page here.

3. Copy your program codes.

4. In the post/reply page click on this symbol </> of the tool menu; as a result, you will find these: [code ] and [ /code ] on the post page.

5. Bring the cursor in the middle of (the place where I have written and)
[ code ]and [ /code ]

6. Pres Ctrl+V on the Keyboard of the PC.

7. See that the codes have appeared on the post page.

8. Press on the Post button of the post/reply page.

9. Observe that your codes have appeared online in a fantastic looking!

datskunchala:
even after trying the above commands i got same output on

Why are you not posting your code?
Without it we can not try things ourselves, a screen shot does not cut it here.

Nowhere do you define a value for chipselect nor do you set it as an output before you write to it.

#include<SPI.h>
#include<SD.h>

char compare[6] = "start";

int i = 0;
const int chipselect = 10;
File sdcard;
char c;


void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  while (!Serial) {
    Serial.print("unable to select serial console\n");
    ;
  }

  Serial.print("detecting sdcard please wait\n");
  if (!SD.begin(chipselect)) {
    while (1);
  }
  
  Serial.print("sdcard detected \n");  
  if (SD.exists("text.dat")) {
    Serial.print("file already exists\n");
  }

    File sdcard = SD.open("text.dat", FILE_WRITE);
    sdcard.println(compare);
    Serial.print("copied text \n");
    sdcard.close();

    
    /* OPENING THE SD CARD FILE AGAIN TO READ BACK */
    sdcard = SD.open("test.txt");
    while(1)
    {
      Serial.print("-");
    char c = (char)sdcard.read();
      Serial.print(c);
      i++;
      if(i> 5) break;
    }
  sdcard.close();
}

void loop() {

}

I have posted the complete code and I have tried to type cast it to other formats like int char float double and string for INT I am getting value=1 for double=1.00 and for char-? and finally, for string -1(no data found according to Arduino pages ) and sometimes white spaces too with serial.println() command
but I want to read the strings so can you tell me where I am wrong

tried to typecast like this:-

c = (char)sdcard.read();
Serial.print(c);

@OP

Try these:

{
  sdcard = SD.open("text.dat", FILE_READ); //you should open that file where you wrote; not 'test.txt"
  if (sdcard)
  {
    while (sdcard.available())                 //not while(1)
    {
      char x = (char)sdcard.read();
      Serial.print(x);
    }
    sdcard.close();
  }
  else
  {
    Serial.println("File can't be opened...!");
  }
}

thank you very much this solved my problem