Skip to main content
`Ctrl`+`K`

# PetscOptionsGetString

Gets the string value for a particular option in the database.

## Synopsis

    #include "petscsys.h"
    PetscErrorCode PetscOptionsGetString(PetscOptions options, const char pre[], const char name[], char string[], size_t len, PetscBool *set) PeNS

Not Collective

## Input Parameters

- options - options database, use `NULL` for default global database

- pre - string to prepend to name or `NULL`

- name - the option one is seeking

- len - maximum length of the string including null termination

## Output Parameters

- string - location to copy string

- set - `PETSC_TRUE` if found, else `PETSC_FALSE`

## Note

if the option is given but no string is provided then an empty string is returned and `set` is given the value of `PETSC_TRUE`

If the user does not use the option then `string` is not changed. Thus you should ALWAYS initialize `string` if you access it without first checking that the `set` flag is true.

## Fortran Notes

The Fortran interface is slightly different from the C/C++ interface. Sample usage in Fortran follows

          character *20    string
          PetscErrorCode   ierr
          PetscBool        set
          call PetscOptionsGetString(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-s',string,set,ierr)

## See Also

`PetscOptionsGetInt()`, `PetscOptionsGetReal()`, `PetscOptionsHasName()`, `PetscOptionsGetIntArray()`, `PetscOptionsGetRealArray()`, `PetscOptionsBool()`, `PetscOptionsName()`, `PetscOptionsBegin()`, `PetscOptionsEnd()`, `PetscOptionsHeadBegin()`, `PetscOptionsStringArray()`, `PetscOptionsRealArray()`, `PetscOptionsScalar()`, `PetscOptionsBoolGroupBegin()`, `PetscOptionsBoolGroup()`, `PetscOptionsBoolGroupEnd()`, `PetscOptionsFList()`, `PetscOptionsEList()`

## Level

beginner

## Location

src/sys/objects/options.c

## Examples

src/dm/impls/stag/tutorials/ex4.c
src/ksp/ksp/tutorials/ex27.c
src/ksp/ksp/tutorials/ex72.c
src/ksp/ksp/tutorials/ex77.c
src/ksp/ksp/tutorials/ex42.c
src/ksp/ksp/tutorials/ex75f.F90
src/dm/label/tutorials/ex1f90.F90
src/ksp/ksp/tutorials/ex75.c
src/ksp/ksp/tutorials/ex76f.F90
src/ksp/ksp/tutorials/ex43.c

Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages